System.Globalization.DateTimeStyles Enumeration

Defines the formatting options that customize string parsing for some date and time parsing methods.

Syntax

[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum DateTimeStyles

Remarks

System.Globalization.DateTimeStyles values can be used with any of the following date and time parsing methods that include a styles parameter to define the interpretation of the style elements that may be present in the string to be parsed:

The ParseExact and TryParseExact methods can use any of the System.Globalization.DateTimeStyles values. However, if none of the Allow* values is selected, the input string must have exactly the same white-space characters as the format string.

If the input string does not contain any indication of the time zone, the date and time parsing methods interpret the value of the date and time string based on the time zone setting for the operating system. To convert the date and time to the Universal Time or Greenwich Mean Time (GMT), the application should use the DateTimeStyles.AdjustToUniversal value. The same effect can be achieved by calling the DateTime.ToUniversalTime or DateTimeOffset.ToUniversalTime method. However, using the DateTimeStyles.AdjustToUniversal value with the date and time parsing method is more efficient.

Members

Member NameDescription
AdjustToUniversal

Date and time are returned as a Coordinated Universal Time (UTC). If the input string denotes a local time, through a time zone specifier or DateTimeStyles.AssumeLocal, the date and time are converted from the local time to UTC. If the input string denotes a UTC time, through a time zone specifier or DateTimeStyles.AssumeUniversal, no conversion occurs. If the input string does not denote a local or UTC time, no conversion occurs and the resulting DateTime.Kind property is DateTimeKind.Unspecified.

AllowInnerWhite

Extra white-space characters in the middle of the string must be ignored during parsing, except if they occur in the System.Globalization.DateTimeFormatInfo format patterns.

AllowLeadingWhite

Leading white-space characters must be ignored during parsing, except if they occur in the System.Globalization.DateTimeFormatInfo format patterns.

AllowTrailingWhite

Trailing white-space characters must be ignored during parsing, except if they occur in the System.Globalization.DateTimeFormatInfo format patterns.

AllowWhiteSpaces

Extra white-space characters anywhere in the string must be ignored during parsing, except if they occur in the System.Globalization.DateTimeFormatInfo format patterns. This value is a combination of the DateTimeStyles.AllowLeadingWhite, DateTimeStyles.AllowTrailingWhite, and DateTimeStyles.AllowInnerWhite values.

AssumeLocal

If no time zone is specified in the parsed string, the string is assumed to denote a local time.

AssumeUniversal

If no time zone is specified in the parsed string, the string is assumed to denote a UTC.

NoCurrentDateDefault

If the parsed string contains only the time and not the date, the parsing methods assume the Gregorian date with year = 1, month = 1, and day = 1. If this value is not used, the current date is assumed.

None

Default formatting options must be used. This value represents the default style for the DateTime.Parse(string), DateTime.ParseExact(string, string, IFormatProvider), and DateTime.TryParse(string, DateTime@) methods.

RoundtripKind

The DateTimeKind field of a date is preserved when a DateTime object is converted to a string using the "o" or "r" standard format specifier, and the string is then converted back to a DateTime object.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0