3

I have run into some code where it does something like this:

SomeDateTimeObject.ToUniversalTime()
                                .ToString("ddd, d MMM yyyy HH:mm:ss +ffff", CultureInfo.InvariantCulture),

Now I am confused what +ffff stands for in this. Also, I would like to get the millisecond part of the datetime along with hours/minutes and seconds. what is the format for that?

tavier
  • 1,744
  • 4
  • 24
  • 53
  • `ffff` are ten thousandths of a second. https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings. Milliseconds are `fff`. – Jasen Sep 15 '17 at 03:34
  • So basically it's the millisecond part of the DateTime? e.g. 2009-06-15T13:45:30.6175000 will give 6175 (which is the milliseconds). is that correct? – tavier Sep 15 '17 at 03:38
  • The fs are fractions of a second. You can move it where you please in the format string. `yyyy-MM-ddTHH:mm:ss.fff` will return 3 digits for the fractional seconds. When you start asking for more precision, the docs warn that the system clock may not actually deliver on that promise. _"The precision of date and time values depends on the resolution of the system clock"_ – Jasen Sep 15 '17 at 03:43
  • Alright, makes sense. So in order to get the milliseconds part of the date time I need to do something like HH:mm:ss.fff maybe. Thanks – tavier Sep 15 '17 at 03:46
  • **Note:** the actual useful answer in the **duplicate** mentioned above is [here](https://stackoverflow.com/a/24728080/585968). Thanks @Jasen –  Sep 15 '17 at 03:54
  • There are also two answers that link to the Microsoft documentation. – Jasen Sep 15 '17 at 03:55

1 Answers1

6

"ff..." is used for fractions of a second

See MSDN for more details of custom date and time formatting.

Dan Nguyen
  • 1,308
  • 6
  • 17