DateTime losing Milliseconds

前端 未结 1 1126
遇见更好的自我
遇见更好的自我 2020-12-21 16:43

I am parsing a date from a file as a string and converting it to DateTime so that I can compare it with a previous date. I am losing the milliseconds when I do

相关标签:
1条回答
  • 2020-12-21 17:07

    CodeCaster already explained your problem, I wanna add this as an answer if he let's me..

    Don't worry! Your milliseconds didn't lost. They are still there. Sounds like you just didn't see them when you try to represent your m_LatestProcessDate and that's probably because your string representation of your DateTime doesn't have milliseconds part.

    enter image description here

    For example, if you use DateTime.ToString() method without any parameter, this method uses "G" standard format of your CurrentCulture.

    This specifier formats your DateTime as ShortDatePattern + LongTimePattern. And no culture have Millisecond part on it's LongTimePattern.

    For example; InvariantCulture has HH:mm:ss format which doesn't represent millisecond part.

    You can see your milliseconds of your m_LatestProcessDate like;

    Console.WriteLine(m_LatestProcessDate.ToString("fff")); // prints 571
    
    0 讨论(0)
提交回复
热议问题