What is the difference between fff and ms in datetime?
DateTime dt = DateTime.Now;
string s1 = dt.ToString("yyyy-MM-dd HH:mm:ss.fff");
string s2 = dt.ToString("yyyy-MM-dd-hh-mm-ss-ms");
The output will be as below:
2018-12-03 14:28:23.357
2018-12-03-02-28-23-2823
You see that 357 is different from 2823. What is the reason? Thanks.
Edit: Thanks all of you. I wonder how ms came out of my mind. Maybe I mix it with Oracle. Haha.
There isn't any ms
format-key to formatting DateTime
in C#. The m
stands for minute and the s
stands for second. So, ms
is just a combination of minute and second along together. For formatting milliseconds in DateTime
the pattern uses f
and F
. What you did actually, was putting a m
beside a s
. So you got 28
beside 23
which results 2823
.
For more information, see the doc: How to: Display Milliseconds in Date and Time Values
Take a look at the docs: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7.2
There is no ms
specifier; what you have is the concatenation of the m
(minutes, 28 in this case) and the s
specifier (seconds, 23), hence 2823.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With