DateTimeStyles Enumeration
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Defines the formatting options that customize string parsing for a number of DateTime and DateTimeOffset parsing methods.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration DateTimeStyles
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum DateTimeStyles
Members
Member name | Description | |
---|---|---|
None | Default formatting options must be used. This value represents the default style for DateTime.Parse, DateTime.ParseExact, and DateTime.TryParse. | |
AllowLeadingWhite | Leading white-space characters must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns. | |
AllowTrailingWhite | Trailing white-space characters must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns. | |
AllowInnerWhite | Extra white-space characters in the middle of the string must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns. | |
AllowWhiteSpaces | Extra white-space characters anywhere in the string must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns. This value is a combination of the AllowLeadingWhite, AllowTrailingWhite, and AllowInnerWhite values. | |
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. | |
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 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 AssumeUniversal, no conversion occurs. If the input string does not denote a local or UTC time, no conversion occurs and the resulting Kind property is Unspecified.
Cannot be used with RoundtripKind. |
|
AssumeLocal | If no time zone is specified in the parsed string, the string is assumed to denote a local time.
Cannot be used with AssumeUniversal or RoundtripKind. |
|
AssumeUniversal | If no time zone is specified in the parsed string, the string is assumed to denote a UTC.
Cannot be used with AssumeLocal or RoundtripKind. |
|
RoundtripKind | For parsing operations using DateTime methods on strings that contain time zone information, tries to prevent the conversion to a local DateTime value with its Kind property set to DateTimeKind.Local. For DateTimeOffset values, this flag has no effect. |
Remarks
The DateTimeStyles enumeration is used as a parameter that controls the parsing operation of the following methods:
DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles)
DateTime.TryParse(String, IFormatProvider, DateTimeStyles, DateTime%)
DateTimeOffset.TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset%)
DateTimeOffset.TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset%)
DateTime.ParseExact(String, String, IFormatProvider, DateTimeStyles)
DateTime.ParseExact(String, array<String[], IFormatProvider, DateTimeStyles)
DateTimeOffset.ParseExact(String, array<String[], IFormatProvider, DateTimeStyles)
DateTimeOffset.ParseExact(String, String, IFormatProvider, DateTimeStyles)
DateTime.TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTime%)
DateTime.TryParseExact(String, array<String[], IFormatProvider, DateTimeStyles, DateTime%)
DateTimeOffset.TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTimeOffset%)
The ParseExact and TryParseExact methods can use any of the 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, parsing methods assume that the date and time represents the local time and either set the DateTime.Kind property to DateTimeKind.Local or set the DateTimeOffset.Offset property to the time zone offset of the local system. To convert this date and time to Coordinated Universal Time (UTC), use the AdjustToUniversal value. The same effect can be achieved using ToUniversalTime. However, using the AdjustToUniversal value is more efficient.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.