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

日期和時間會以 Coordinated Universal Time (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.

適用於

另請參閱