DateTimeStyles 枚举

定义

定义一些格式设置选项,这些选项可自定义许多日期和时间分析方法的字符串分析方法。Defines the formatting options that customize string parsing for some date and time parsing methods.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class DateTimeStyles
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum DateTimeStyles
type DateTimeStyles = 
Public Enum DateTimeStyles
继承
DateTimeStyles
属性

字段

AdjustToUniversal 16

以协调世界时 (UTC) 形式返回日期和时间。Date and time are returned as a Coordinated Universal Time (UTC). 如果输入字符串表示本地时间(通过时区说明符或 AssumeLocal),则会将日期和时间从本地时间转换为 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. 如果输入字符串表示 UTC 时间(通过时区说明符或 AssumeUniversal),则不进行任何转换。If the input string denotes a UTC time, through a time zone specifier or AssumeUniversal, no conversion occurs. 如果输入字符串不表示本地时间或 UTC 时间,则不进行任何转换,并且生成的 Kind 属性为 UnspecifiedIf the input string does not denote a local or UTC time, no conversion occurs and the resulting Kind property is Unspecified. 此值不能与 RoundtripKind 一起使用。This value cannot be used with RoundtripKind.

AllowInnerWhite 4

在分析期间必须忽略字符串中间的多余空白字符,但空白字符出现在 DateTimeFormatInfo 格式模式中的情况除外。Extra white-space characters in the middle of the string must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns.

AllowLeadingWhite 1

在分析期间必须忽略前导空白字符,但空白字符出现在 DateTimeFormatInfo 格式模式中的情况除外。Leading white-space characters must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns.

AllowTrailingWhite 2

在分析期间必须忽略尾随空白字符,但空白字符出现在 DateTimeFormatInfo 格式模式中的情况除外。Trailing white-space characters must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns.

AllowWhiteSpaces 7

在分析期间必须忽略字符串任意位置的多余空白字符,但空白字符出现在 DateTimeFormatInfo 格式模式中的情况除外。Extra white-space characters anywhere in the string must be ignored during parsing, except if they occur in the DateTimeFormatInfo format patterns. 该值是 AllowLeadingWhiteAllowTrailingWhiteAllowInnerWhite 值的组合。This value is a combination of the AllowLeadingWhite, AllowTrailingWhite, and AllowInnerWhite values.

AssumeLocal 32

如果分析的字符串中未指定任何时区,则假定该字符串表示本地时间。If no time zone is specified in the parsed string, the string is assumed to denote a local time. 此值不能与 AssumeUniversalRoundtripKind 一起使用。This value cannot be used with AssumeUniversal or RoundtripKind.

AssumeUniversal 64

如果分析的字符串中未指定任何时区,则假定该字符串表示 UTC。If no time zone is specified in the parsed string, the string is assumed to denote a UTC. 此值不能与 AssumeLocalRoundtripKind 一起使用。This value cannot be used with AssumeLocal or RoundtripKind.

NoCurrentDateDefault 8

如果分析的字符串只包含时间而不包含日期,则分析方法会假定以下公历日期:年 = 1、月 = 1 并且日 = 1。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 0

必须使用默认格式设置选项。Default formatting options must be used. 此值表示 Parse(String)ParseExact(String, String, IFormatProvider)TryParse(String, DateTime) 方法的默认样式。This value represents the default style for the Parse(String), ParseExact(String, String, IFormatProvider), and TryParse(String, DateTime) methods.

RoundtripKind 128

在使用“o”或“r”标准格式说明符将 DateTimeKind 对象先转换为字符串,然后再将该字符串转换回 DateTime 对象时,将保留日期的 DateTime 字段。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.

注解

DateTimeStyles值可用于以下任何日期和时间分析方法, 这些方法包括一个styles参数, 用于定义可在要分析的字符串中存在的样式元素的解释: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:

和方法可以使用任意值。 DateTimeStyles ParseExact TryParseExactThe ParseExact and TryParseExact methods can use any of the DateTimeStyles values. 但是, 如果未选择任何Allow*值, 则输入字符串必须与格式字符串具有完全相同的空白字符。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. 若要将日期和时间转换为通用时间或格林尼治标准时间 (GMT), 应用程序应使用AdjustToUniversal值。To convert the date and time to the Universal Time or Greenwich Mean Time (GMT), the application should use the AdjustToUniversal value. 可以通过调用DateTime.ToUniversalTimeDateTimeOffset.ToUniversalTime方法来实现同样的效果。The same effect can be achieved by calling the DateTime.ToUniversalTime or DateTimeOffset.ToUniversalTime method. 但是, AdjustToUniversal将值用于日期和时间分析方法更有效。However, using the AdjustToUniversal value with the date and time parsing method is more efficient.

适用于

另请参阅