DateTimeOffset.Parse DateTimeOffset.Parse DateTimeOffset.Parse DateTimeOffset.Parse Method

定义

将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date and time to its DateTimeOffset equivalent.

重载

Parse(String) Parse(String) Parse(String) Parse(String)

将日期、时间和偏移量的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date, time, and offset to its DateTimeOffset equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

使用指定的特定于区域性的格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information.

Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)
Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles)

使用指定的区域性特定格式信息和格式设置样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.

注解

重要

日本历法中的年号是根据天皇统治来命名的,因此预计会发生变化。Eras in the Japanese calendars are based on the emperor's reign and are therefore expected to change. 例如,2019 年 5 月 1 日在 JapaneseCalendarJapaneseLunisolarCalendar 中标志着令和年号的开始。For example, May 1, 2019 marked the beginning of the Reiwa era in the JapaneseCalendar and JapaneseLunisolarCalendar. 这种年号的变化会影响使用这些日历的所有应用程序。Such a change of era affects all applications that use these calendars. 请参阅 Handling a new era in the Japanese calendar in .NET(使用 .NET 处理日语日历中的新元号),了解详细信息并确定是否会影响你的应用程序。See Handling a new era in the Japanese calendar in .NET for more information and to determine whether your applications are affected. 请参阅针对日语元号更改准备应用程序,了解有关在 Windows 系统上测试应用程序以确保针对元号更改的准备情况信息。See Prepare your application for the Japanese era change for information on testing your applications on Windows systems to ensure their readiness for the era change. 有关 .Net 中支持多个年号日历的功能,以及在使用支持多个年号的日历时的最佳做法,请参阅使用年号See Working with eras for features in .NET that support calendars with multiple eras and for best practices when working with calendars that support multiple eras.

Parse(String) Parse(String) Parse(String) Parse(String)

将日期、时间和偏移量的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date, time, and offset to its DateTimeOffset equivalent.

public:
 static DateTimeOffset Parse(System::String ^ input);
public static DateTimeOffset Parse (string input);
static member Parse : string -> DateTimeOffset
Public Shared Function Parse (input As String) As DateTimeOffset

参数

input
String String String String

包含要转换的日期和时间的字符串。A string that contains a date and time to convert.

返回

一个对象,它等效于 input 中包含的日期和时间。An object that is equivalent to the date and time that is contained in input.

异常

偏移量大于 14 小时或小于 -14 小时。The offset is greater than 14 hours or less than -14 hours.

input 不包含日期和时间的有效字符串表示形式。input does not contain a valid string representation of a date and time.

- 或 --or- input 包含不带日期或时间的偏移量值的字符串表示形式。input contains the string representation of an offset value without a date or time.

示例

下面的示例调用Parse(String)方法来分析多个日期和时间字符串。The following example calls the Parse(String) method to parse several date and time strings. 该示例包括从2007年3月22日到区域性为 en-us 的系统的输出。The example includes output from March 22, 2007, on a system whose culture is en-us.

string dateString;
DateTimeOffset offsetDate; 

// String with date only
dateString = "05/01/2008";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());

// String with time only
dateString = "11:36 PM";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());

// String with date and offset 
dateString = "05/01/2008 +1:00";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());

// String with day abbreviation
dateString = "Thu May 01, 2008";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());
Dim dateString As String
Dim offsetDate As DateTimeOffset

' String with date only
dateString = "05/01/2008"
offsetDate = DateTimeOffset.Parse(dateString)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 12:00:00 AM -07:00  

' String with time only
dateString = "11:36 PM"
offsetDate = DateTimeOffset.Parse(dateString)
Console.WriteLine(offsetDate.ToString())   ' Displays 3/26/2007 11:36:00 PM -07:00

' String with date and offset 
dateString = "05/01/2008 +7:00"
offsetDate = DateTimeOffset.Parse(dateString)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 12:00:00 AM +07:00

' String with day abbreviation
dateString = "Thu May 01, 2008"
offsetDate = DateTimeOffset.Parse(dateString)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 12:00:00 AM -07:00

注解

Parse(String)分析一个字符串,其中包含三个元素,这些元素可按任意顺序出现并由空格分隔。Parse(String) parses a string with three elements that can appear in any order and are delimited by white space. 这三个元素如下表中所示。These three elements are as shown in the following table.

元素Element 示例Example
<日期 ><Date> "2/10/2007""2/10/2007"
<时间 ><Time> "1:02:03 PM""1:02:03 PM"
<Offset><Offset> "-7:30""-7:30"

尽管这些元素中的每个元素<都是可选的,但 Offset > 不能单独出现。Although each of these elements is optional, <Offset> cannot appear by itself. 它必须与<日期 > 或<时间 > 一起提供。It must be provided together with either <Date> or <Time>. 如果<缺少日期 >,则其默认值为当前日期。If <Date> is missing, its default value is the current day. 如果<缺少时间 >,则其默认值为 12:00:00 AM。If <Time> is missing, its default value is 12:00:00 AM. 如果<存在日期 > 但其年份组成部分只包含两个数字,则将根据Calendar.TwoDigitYearMax属性的值将其转换为当前区域性当前日历中的年份。If <Date> is present but its year component consists of only two digits, it is converted to a year in the current culture's current calendar based on the value of the Calendar.TwoDigitYearMax property. 如果<缺少 Offset >,则其默认值为本地时区的偏移量。If <Offset> is missing, its default value is the offset of the local time zone. <偏移量 > 可以表示与协调世界时(UTC)之间的负值或正偏移量。<Offset> can represent either a negative or a positive offset from Coordinated Universal Time (UTC). 在任一情况下<,偏移 > 都必须包含一个符号符号。In either case, <Offset> must include a sign symbol.

通过使用为当前区域性初始化的DateTimeFormatInfo对象中的格式设置信息对字符串进行分析。inputThe input string is parsed by using the formatting information in a DateTimeFormatInfo object that is initialized for the current culture. 若要分析包含指定格式的字符串,该字符串不一定对应于当前区域性的格式设置,请使用ParseExact方法并提供格式说明符。To parse a string that contains designated formatting that does not necessarily correspond to the formatting of the current culture, use the ParseExact method and provide a format specifier.

另请参阅

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

使用指定的特定于区域性的格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information.

public:
 static DateTimeOffset Parse(System::String ^ input, IFormatProvider ^ formatProvider);
public static DateTimeOffset Parse (string input, IFormatProvider formatProvider);
static member Parse : string * IFormatProvider -> DateTimeOffset
Public Shared Function Parse (input As String, formatProvider As IFormatProvider) As DateTimeOffset

参数

input
String String String String

包含要转换的日期和时间的字符串。A string that contains a date and time to convert.

formatProvider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

一个对象,提供有关 input 的区域性特定的格式信息。An object that provides culture-specific format information about input.

返回

一个对象,它等效于 input 中包含的日期和时间,由 formatProvider 指定。An object that is equivalent to the date and time that is contained in input, as specified by formatProvider.

异常

偏移量大于 14 小时或小于 -14 小时。The offset is greater than 14 hours or less than -14 hours.

input 不包含日期和时间的有效字符串表示形式。input does not contain a valid string representation of a date and time.

-or- input 包含不带日期或时间的偏移量值的字符串表示形式。input contains the string representation of an offset value without a date or time.

示例

下面的示例分析为 fr-fr 区域性设置格式的日期和时间字符串,并使用本地系统的默认 en-us 区域性显示它们。The following example parses date and time strings that are formatted for the fr-fr culture and displays them using the local system's default en-us culture.

DateTimeFormatInfo fmt = new CultureInfo("fr-fr").DateTimeFormat;
string dateString;
DateTimeOffset offsetDate;

dateString = "03-12-07";
offsetDate = DateTimeOffset.Parse(dateString, fmt);
Console.WriteLine("{0} returns {1}", 
                  dateString, 
                  offsetDate.ToString());

dateString = "15/09/07 08:45:00 +1:00";
offsetDate = DateTimeOffset.Parse(dateString, fmt);
Console.WriteLine("{0} returns {1}", 
                  dateString, 
                  offsetDate.ToString());

dateString = "mar. 1 janvier 2008 1:00:00 +1:00"; 
offsetDate = DateTimeOffset.Parse(dateString, fmt);
Console.WriteLine("{0} returns {1}", 
                  dateString, 
                  offsetDate.ToString());
// The example displays the following output to the console:
//    03-12-07 returns 12/3/2007 12:00:00 AM -08:00
//    15/09/07 08:45:00 +1:00 returns 9/15/2007 8:45:00 AM +01:00
//    mar. 1 janvier 2008 1:00:00 +1:00 returns 1/1/2008 1:00:00 AM +01:00                              
Dim fmt As DateTimeFormatInfo = New CultureInfo("fr-fr").DateTimeFormat
Dim dateString As String
Dim offsetDate As DateTimeOffset

dateString = "03-12-07"
offsetDate = DateTimeOffset.Parse(dateString, fmt)
Console.WriteLine("{0} returns {1}", _
                  dateString, _
                  offsetDate.ToString())

dateString = "15/09/07 08:45:00 +1:00"
offsetDate = DateTimeOffset.Parse(dateString, fmt)
Console.WriteLine("{0} returns {1}", _
                  dateString, _
                  offsetDate.ToString())

dateString = "mar. 1 janvier 2008 1:00:00 +1:00" 
offsetDate = DateTimeOffset.Parse(dateString, fmt)
Console.WriteLine("{0} returns {1}", _
                  dateString, _
                  offsetDate.ToString())
' The example displays the following output to the console:
'    03-12-07 returns 12/3/2007 12:00:00 AM -08:00
'    15/09/07 08:45:00 +1:00 returns 9/15/2007 8:45:00 AM +01:00
'    mar. 1 janvier 2008 1:00:00 +1:00 returns 1/1/2008 1:00:00 AM +01:00                              

注解

此方法分析一个字符串,其中包含三个元素,这些元素可按任意顺序出现并由空格分隔。This method parses a string with three elements that can appear in any order and are delimited by white space. 下表显示了这三个元素。These three elements are shown in the following table.

元素Element 示例Example
<日期 ><Date> "2/10/2007""2/10/2007"
<时间 ><Time> "1:02:03 PM""1:02:03 PM"
<Offset><Offset> "-7:30""-7:30"

尽管这些元素中的每个元素<都是可选的,但 Offset > 不能单独出现。Although each of these elements is optional, <Offset> cannot appear by itself. 它必须与<日期 > 或<时间 > 一起提供。It must be provided together with either <Date> or <Time>. 如果<缺少日期 >,则其默认值为当前日期。If <Date> is missing, its default value is the current day. 如果<存在日期 > 但其年份组成部分只包含两个数字,则将根据Calendar.TwoDigitYearMax属性的值将其转换provider为参数的当前日历中的年份。If <Date> is present but its year component consists of only two digits, it is converted to a year in the provider parameter's current calendar based on the value of the Calendar.TwoDigitYearMax property. 如果<缺少时间 >,则其默认值为 12:00:00 AM。If <Time> is missing, its default value is 12:00:00 AM. 如果<缺少 Offset >,则其默认值为本地时区的偏移量。If <Offset> is missing, its default value is the offset of the local time zone. <偏移量 > 可以表示与协调世界时(UTC)之间的负值或正偏移量。<Offset> can represent either a negative or a positive offset from Coordinated Universal Time (UTC). 在任一情况下<,偏移 > 都必须包含一个符号符号。In either case, <Offset> must include a sign symbol.

这三个元素的格式由formatProvider参数定义,可以是以下之一:The format of these three elements is defined by the formatProvider parameter, which can be either of the following:

如果formatprovidernullCultureInfo则使用对应于当前区域性的对象。If formatprovider is null, the CultureInfo object that corresponds to the current culture is used.

Offset > 中<使用的正号或负号必须是 + 或-。The positive or negative sign used in <Offset> must be either + or -. PositiveSign不由NegativeSign 参数formatProviderNumberFormatInfo对象的或属性定义。It is not defined by the PositiveSign or NegativeSign properties of the NumberFormatInfo object of the formatProvider parameter.

另请参阅

Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)

public static DateTimeOffset Parse (ReadOnlySpan<char> input, IFormatProvider formatProvider = null, System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None);
static member Parse : ReadOnlySpan<char> * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function Parse (input As ReadOnlySpan(Of Char), Optional formatProvider As IFormatProvider = null, Optional styles As DateTimeStyles = System.Globalization.DateTimeStyles.None) As DateTimeOffset

参数

返回

Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles)

使用指定的区域性特定格式信息和格式设置样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.

public:
 static DateTimeOffset Parse(System::String ^ input, IFormatProvider ^ formatProvider, System::Globalization::DateTimeStyles styles);
public static DateTimeOffset Parse (string input, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles);
static member Parse : string * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function Parse (input As String, formatProvider As IFormatProvider, styles As DateTimeStyles) As DateTimeOffset

参数

input
String String String String

包含要转换的日期和时间的字符串。A string that contains a date and time to convert.

formatProvider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

一个对象,提供有关 input 的区域性特定的格式信息。An object that provides culture-specific format information about input.

styles
DateTimeStyles DateTimeStyles DateTimeStyles DateTimeStyles

枚举值的一个按位组合,指示 input 所允许的格式。A bitwise combination of enumeration values that indicates the permitted format of input. 要指定的一个典型值为 NoneA typical value to specify is None.

返回

一个对象,它等效于 input 中包含的日期和时间,由 formatProviderstyles 指定。An object that is equivalent to the date and time that is contained in input as specified by formatProvider and styles.

异常

偏移量大于 14 小时或小于 -14 小时。The offset is greater than 14 hours or less than -14 hours.

-or- styles 不是有效的 DateTimeStyles 值。styles is not a valid DateTimeStyles value.

-or- styles 包含不支持的 DateTimeStyles 值。styles includes an unsupported DateTimeStyles value.

-or- styles 包含不能一起使用的 DateTimeStyles 值。styles includes DateTimeStyles values that cannot be used together.

input 不包含日期和时间的有效字符串表示形式。input does not contain a valid string representation of a date and time.

-or- input 包含不带日期或时间的偏移量值的字符串表示形式。input contains the string representation of an offset value without a date or time.

示例

下面的示例演示了将DateTimeStyles.AssumeLocalDateTimeStyles.AssumeUniversalDateTimeStyles.AdjustToUniversal值传递给styles Parse(String, IFormatProvider, DateTimeStyles)方法的参数的影响。The following example illustrates the effect of passing the DateTimeStyles.AssumeLocal, DateTimeStyles.AssumeUniversal, and DateTimeStyles.AdjustToUniversal values to the styles parameter of the Parse(String, IFormatProvider, DateTimeStyles) method.

string dateString;
DateTimeOffset offsetDate;

dateString = "05/01/2008 6:00:00";
// Assume time is local 
offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeLocal);
Console.WriteLine(offsetDate.ToString());   // Displays 5/1/2008 6:00:00 AM -07:00

// Assume time is UTC
offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeUniversal);
Console.WriteLine(offsetDate.ToString());   // Displays 5/1/2008 6:00:00 AM +00:00

// Parse and convert to UTC 
dateString = "05/01/2008 6:00:00AM +5:00";
offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AdjustToUniversal);
Console.WriteLine(offsetDate.ToString());   // Displays 5/1/2008 1:00:00 AM +00:00
Dim dateString As String
Dim offsetDate As DateTimeOffset

dateString = "05/01/2008 6:00:00"
' Assume time is local 
offsetDate = DateTimeOffset.Parse(dateString, Nothing, DateTimeStyles.AssumeLocal)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 6:00:00 AM -07:00

' Assume time is UTC
offsetDate = DateTimeOffset.Parse(dateString, Nothing, DateTimeStyles.AssumeUniversal)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 6:00:00 AM +00:00

' Parse and convert to UTC 
dateString = "05/01/2008 6:00:00AM +5:00"
offsetDate = DateTimeOffset.Parse(dateString, Nothing, DateTimeStyles.AdjustToUniversal)
Console.WriteLine(offsetDate.ToString())   ' Displays 5/1/2008 1:00:00 AM +00:00

注解

此方法分析一个字符串,其中包含三个元素,这些元素可按任意顺序出现并由空格分隔。This method parses a string with three elements that can appear in any order and are delimited by white space. 下表显示了这三个元素。These three elements are shown in the following table.

元素Element 示例Example
<日期 ><Date> "2/10/2007""2/10/2007"
<时间 ><Time> "1:02:03 PM""1:02:03 PM"
<Offset><Offset> "-7:30""-7:30"

尽管这些元素中的每个元素<都是可选的,但 Offset > 不能单独出现。Although each of these elements is optional, <Offset> cannot appear by itself. 它必须与<日期 > 或<时间 > 一起提供。It must be provided together with either <Date> or <Time>. 如果<缺少日期 >,则其默认值为当前日期。If <Date> is missing, its default value is the current day. 如果<存在日期 > 但其年份组成部分只包含两个数字,则将根据Calendar.TwoDigitYearMax属性的值将其转换provider为参数的当前日历中的年份。If <Date> is present but its year component consists of only two digits, it is converted to a year in the provider parameter's current calendar based on the value of the Calendar.TwoDigitYearMax property. 如果<缺少时间 >,则其默认值为 12:00:00 AM。If <Time> is missing, its default value is 12:00:00 AM. 如果<缺少 Offset >,则其默认值为本地时区的偏移量,或者TimeSpan.Zero ,如果在styles参数中DateTimeStyles.AdjustToUniversal指定DateTimeStyles.AssumeUniversal了或值,则为。If <Offset> is missing, its default value is the offset of the local time zone, or TimeSpan.Zero if either the DateTimeStyles.AdjustToUniversal or DateTimeStyles.AssumeUniversal value is specified in the styles parameter. 如果<> 存在偏移量,则它可以表示与协调世界时(UTC)之间的负值或正偏移量。If <Offset> is present, it can represent either a negative or a positive offset from Coordinated Universal Time (UTC). 在任一情况下<,偏移 > 都必须包含一个符号符号。In either case, <Offset> must include a sign symbol.

这三个元素的格式由formatProvider参数定义,可以是以下之一:The format of these three elements is defined by the formatProvider parameter, which can be either of the following:

每个元素还可以用前导或尾随空格括起来, <日期 > 和<时间 > 元素可以包含内部空格(如6: 00:00)。Each element can also be enclosed by leading or trailing white space, and the <Date> and <Time> elements can include inner white space (such as 6: 00:00). <只有偏移 > 组件不能包含内部空格。Only the <Offset> component cannot include inner white space.

如果formatprovidernullCultureInfo则使用对应于当前区域性的对象。If formatprovider is null, the CultureInfo object that corresponds to the current culture is used.

Offset > 中<使用的正号或负号必须是 + 或-。The positive or negative sign used in <Offset> must be either + or -. PositiveSign它不是由NegativeSign 参数formatProvider返回的NumberFormatInfo对象的或属性定义的。It is not defined by the PositiveSign or NegativeSign properties of the NumberFormatInfo object returned by the formatProvider parameter.

下表显示了支持的System.Globalization.DateTimeStyles枚举的成员。The following table shows the members of the System.Globalization.DateTimeStyles enumeration that are supported.

DateTimeStyles 成员DateTimeStyles member 说明Description
AdjustToUniversal 分析由input表示的字符串,如有必要,将其转换为 UTC。Parses the string represented by input and, if necessary, converts it to UTC. 它等效于分析字符串,然后调用DateTimeOffset.ToUniversalTime返回DateTimeOffset对象的方法。It is equivalent to parsing a string and then calling the DateTimeOffset.ToUniversalTime method of the returned DateTimeOffset object.
AllowInnerWhite 虽然有效,但会忽略此值。Although valid, this value is ignored. <日期 > 和<时间 > 元素中允许有内部空格。Inner white space is permitted in the <Date> and <Time> elements.
AllowLeadingWhite 虽然有效,但会忽略此值。Although valid, this value is ignored. 在分析字符串中的每个组件前面都允许使用前导空格。Leading white space is permitted in front of each component in the parsed string.
AllowTrailingWhite 虽然有效,但会忽略此值。Although valid, this value is ignored. 在分析字符串中的每个组件前面都允许尾随空格。Trailing white space is permitted in front of each component in the parsed string.
AllowWhiteSpaces 这是默认行为。This is the default behavior. 不能通过提供限制性更强DateTimeStyles的枚举值( DateTimeStyles.None如)来重写它。It cannot be overridden by supplying a more restrictive DateTimeStyles enumeration value, such as DateTimeStyles.None.
AssumeLocal 指示如果input参数<缺少偏移 > 元素,则应提供本地时区的偏移量。Indicates that, if the input parameter lacks an <Offset> element, the offset of the local time zone should be provided. 这是Parse方法的默认行为。This is the default behavior of the Parse method.
AssumeUniversal 指示如果input参数<缺少偏移 > 元素,则应提供 UTC 偏移量(00:00)。Indicates that, if the input parameter lacks an <Offset> element, the UTC offset (00:00) should be provided.
None 虽然有效,但此值将被忽略且不起作用。Although valid, this value is ignored and has no effect.
RoundtripKind 由于结构不Kind包含属性,因此此值不起作用。 DateTimeOffsetBecause the DateTimeOffset structure does not include a Kind property, this value has no effect.

只支持DateTimeStyles.NoCurrentDateDefault值。Only the DateTimeStyles.NoCurrentDateDefault value is not supported. 如果参数styles中包含此值,则ArgumentException会引发。An ArgumentException is thrown if this value is included in the styles parameter.

另请参阅

适用于