DateTimeStyles Enum

Definition

定义用来自定义某些日期和事件分析方法的字符串分析的格式选项。Defines the formatting options that customize string parsing for some date and time parsing methods.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class DateTimeStyles
[System.Flags]
public enum DateTimeStyles
[System.Flags]
[System.Serializable]
public enum DateTimeStyles
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum DateTimeStyles
type DateTimeStyles = 
Public Enum DateTimeStyles
Inheritance
DateTimeStyles
Attributes

Fields

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. 如果输入字符串通过时区说明符或 AssumeUniversal 表示 UTC 时间,则不会进行任何转换。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”标准格式说明符将 DateTime 对象转换为字符串时,将保存日期的 DateTimeKind 字段,然后将该字符串转换回 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.

Remarks

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:

ParseExactTryParseExact 方法可以使用任意 DateTimeStyles 值。The 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.

Applies to

See also