且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DateTime.ParseExact省略在C#毫秒?

更新时间:2023-02-27 07:43:43

这不是ommitting你只是通过检查调试器和调试器显示它使用是上午还是下午,它doenot显示毫秒组成部分。

it's not ommitting you are just checking through debugger and debugger shows it using AM or PM ,it doenot show milliseconds part.

试试这个:

DateTime dt=DateTime.ParseExact(datestring, "yyyy/MM/dd HH:mm:ss.fff",null);
Console.WriteLine(dt.ToString("yyyy/MM/dd HH:mm:ss.fff"));

编辑:字符串从您的评论但我需要在日期时间的答案,而不是

您已经将DateTime包括毫秒只是调试器不显示,因为 (正如中提到的评论蚂蚁P )调试器调用的无参数的重载的ToString()方法,它显示了日期时间 $没有毫秒。

You have already the DateTime including MilliSeconds just debugger is not showing because (As mentioned in comment by Ant P) Debugger calls the Parameterless overload of ToString() method which shows the DateTime without MilliSeconds.