CSharp - Format DateTimeStyles Type


DateTimeStyles is a flags enum that provides additional instructions when calling Parse on a DateTime(Offset).

Here are its members:

  • None,
  • AllowLeadingWhite,
  • AllowTrailingWhite,
  • AllowInnerWhite,
  • AssumeLocal,
  • AssumeUniversal,
  • AdjustToUniversal,
  • NoCurrentDateDefault,
  • RoundTripKind

There is also a composite member, AllowWhiteSpaces:

AllowWhiteSpaces = AllowLeadingWhite | AllowTrailingWhite | AllowInnerWhite

The default is None.

AssumeLocal and AssumeUniversal apply if the string doesn't have a time zone suffix (such as Z or +9:00).

AdjustToUniversal still honors time zone suffixes, but then converts to UTC using the current regional settings.

When parsing a string of time with no date, today's date is applied by default.

If you apply the NoCurrentDateDefault flag, however, it uses 1st January 0001.