DateTime.GetDateTimeFormats 方法
定义
将此实例的值转换为标准日期和时间格式说明符支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the standard date and time format specifiers.
重载
| GetDateTimeFormats() |
将此实例的值转换为标准日期和时间格式说明符支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the standard date and time format specifiers. |
| GetDateTimeFormats(Char) |
将此实例的值转换为指定的标准日期和时间格式说明符支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier. |
| GetDateTimeFormats(IFormatProvider) |
将此实例的值转换为标准日期和时间格式说明符和指定的区域性特定格式信息支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the standard date and time format specifiers and the specified culture-specific formatting information. |
| GetDateTimeFormats(Char, IFormatProvider) |
将此实例的值转换为指定的标准日期和时间格式说明符和区域性特定格式信息支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier and culture-specific formatting information. |
注解
重要
不应假设多次调用 GetDateTimeFormats 重载将返回相同的数据。You should not assume that multiple calls to the GetDateTimeFormats overloads will return identical data. 根据特定的重载,此方法返回的数据可能会更改(如果当前区域性发生更改、用户重写单独的区域性设置或对系统的区域性数据进行更新)。Depending on the specific overload, the data returned by this method can change if the current culture changes, the user overrides individual cultural settings, or an update occurs to the system's cultural data.
GetDateTimeFormats()
将此实例的值转换为标准日期和时间格式说明符支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the standard date and time format specifiers.
public:
cli::array <System::String ^> ^ GetDateTimeFormats();
public string[] GetDateTimeFormats ();
member this.GetDateTimeFormats : unit -> string[]
Public Function GetDateTimeFormats () As String()
返回
- String[]
字符串数组,其中每个元素都表示此实例的以标准日期和时间格式说明符之一进行格式设置的一个值。A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
示例
下面的示例演示 DateTime.GetDateTimeFormats() 方法。The following example demonstrates the DateTime.GetDateTimeFormats() method. 它使用计算机的当前区域性中所有可能的标准日期和时间格式显示日期的字符串表示形式,在本例中为 en-us。It displays the string representation of a date using all possible standard date and time formats in the computer's current culture, which in this case is en-US.
DateTime july28 = DateTime(2009, 7, 28, 5, 23, 15, 16);
array<String^>^july28Formats = july28.GetDateTimeFormats();
// Print [Out] july28* in all DateTime formats using the default culture.
System::Collections::IEnumerator^ myEnum = july28Formats->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ format = safe_cast<String^>(myEnum->Current);
System::Console::WriteLine( format );
}
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);
string[] july28Formats = july28.GetDateTimeFormats();
// Print out july28 in all DateTime formats using the default culture.
foreach (string format in july28Formats) {
Console.WriteLine(format);
}
Dim july28 As New DateTime(2009, 7, 28, 5, 23, 15, 16)
Dim july28Formats As String()
july28Formats = july28.GetDateTimeFormats()
' Print out july28 in all DateTime formats using the default culture.
For Each format As String In july28Formats
Console.WriteLine(format)
Next
该示例显示以下输出:The example displays the following output:
7/28/2009
7/28/09
07/28/09
07/28/2009
09/07/28
2009-07-28
28-Jul-09
Tuesday, July 28, 2009
July 28, 2009
Tuesday, 28 July, 2009
28 July, 2009
Tuesday, July 28, 2009 5:23 AM
Tuesday, July 28, 2009 05:23 AM
Tuesday, July 28, 2009 5:23
Tuesday, July 28, 2009 05:23
July 28, 2009 5:23 AM
July 28, 2009 05:23 AM
July 28, 2009 5:23
July 28, 2009 05:23
Tuesday, 28 July, 2009 5:23 AM
Tuesday, 28 July, 2009 05:23 AM
Tuesday, 28 July, 2009 5:23
Tuesday, 28 July, 2009 05:23
28 July, 2009 5:23 AM
28 July, 2009 05:23 AM
28 July, 2009 5:23
28 July, 2009 05:23
Tuesday, July 28, 2009 5:23:15 AM
Tuesday, July 28, 2009 05:23:15 AM
Tuesday, July 28, 2009 5:23:15
Tuesday, July 28, 2009 05:23:15
July 28, 2009 5:23:15 AM
July 28, 2009 05:23:15 AM
July 28, 2009 5:23:15
July 28, 2009 05:23:15
Tuesday, 28 July, 2009 5:23:15 AM
Tuesday, 28 July, 2009 05:23:15 AM
Tuesday, 28 July, 2009 5:23:15
Tuesday, 28 July, 2009 05:23:15
28 July, 2009 5:23:15 AM
28 July, 2009 05:23:15 AM
28 July, 2009 5:23:15
28 July, 2009 05:23:15
7/28/2009 5:23 AM
7/28/2009 05:23 AM
7/28/2009 5:23
7/28/2009 05:23
7/28/09 5:23 AM
7/28/09 05:23 AM
7/28/09 5:23
7/28/09 05:23
07/28/09 5:23 AM
07/28/09 05:23 AM
07/28/09 5:23
07/28/09 05:23
07/28/2009 5:23 AM
07/28/2009 05:23 AM
07/28/2009 5:23
07/28/2009 05:23
09/07/28 5:23 AM
09/07/28 05:23 AM
09/07/28 5:23
09/07/28 05:23
2009-07-28 5:23 AM
2009-07-28 05:23 AM
2009-07-28 5:23
2009-07-28 05:23
28-Jul-09 5:23 AM
28-Jul-09 05:23 AM
28-Jul-09 5:23
28-Jul-09 05:23
7/28/2009 5:23:15 AM
7/28/2009 05:23:15 AM
7/28/2009 5:23:15
7/28/2009 05:23:15
7/28/09 5:23:15 AM
7/28/09 05:23:15 AM
7/28/09 5:23:15
7/28/09 05:23:15
07/28/09 5:23:15 AM
07/28/09 05:23:15 AM
07/28/09 5:23:15
07/28/09 05:23:15
07/28/2009 5:23:15 AM
07/28/2009 05:23:15 AM
07/28/2009 5:23:15
07/28/2009 05:23:15
09/07/28 5:23:15 AM
09/07/28 05:23:15 AM
09/07/28 5:23:15
09/07/28 05:23:15
2009-07-28 5:23:15 AM
2009-07-28 05:23:15 AM
2009-07-28 5:23:15
2009-07-28 05:23:15
28-Jul-09 5:23:15 AM
28-Jul-09 05:23:15 AM
28-Jul-09 5:23:15
28-Jul-09 05:23:15
July 28
July 28
2009-07-28T05:23:15.0160000
2009-07-28T05:23:15.0160000
Tue, 28 Jul 2009 05:23:15 GMT
Tue, 28 Jul 2009 05:23:15 GMT
2009-07-28T05:23:15
5:23 AM
05:23 AM
5:23
05:23
5:23:15 AM
05:23:15 AM
5:23:15
05:23:15
2009-07-28 05:23:15Z
Tuesday, July 28, 2009 12:23:15 PM
Tuesday, July 28, 2009 12:23:15 PM
Tuesday, July 28, 2009 12:23:15
Tuesday, July 28, 2009 12:23:15
July 28, 2009 12:23:15 PM
July 28, 2009 12:23:15 PM
July 28, 2009 12:23:15
July 28, 2009 12:23:15
Tuesday, 28 July, 2009 12:23:15 PM
Tuesday, 28 July, 2009 12:23:15 PM
Tuesday, 28 July, 2009 12:23:15
Tuesday, 28 July, 2009 12:23:15
28 July, 2009 12:23:15 PM
28 July, 2009 12:23:15 PM
28 July, 2009 12:23:15
28 July, 2009 12:23:15
July, 2009
July, 2009
注解
方法返回的字符串数组等效于将 DateTime.GetDateTimeFormats() 通过单独调用返回的字符串数组 DateTime.GetDateTimeFormats(Char) 与 "d"、"d"、"f"、"f"、"g"、"g"、"m"、"o"、"r"、"s"、"t"、"t"、"u"、"u" 和 "y" 标准格式字符串。The string array returned by the DateTime.GetDateTimeFormats() method is equivalent to combining the string arrays returned by separate calls to the DateTime.GetDateTimeFormats(Char) method with the "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U", and "y" standard format strings. 有关标准格式说明符的详细信息,请参阅 标准日期和时间格式字符串。For more information about standard format specifiers, see Standard Date and Time Format Strings.
使用当前区域性中的信息设置返回值的每个元素的格式。Each element of the return value is formatted using information from the current culture. 有关当前区域性的区域性特定格式设置信息的详细信息,请参阅 CultureInfo.CurrentCulture 。For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.
重要
由于此方法使用区分区域性的数据,因此不应假定对方法的多个调用将返回相同的数据。Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data. 如果当前区域性发生更改、用户重写单独的区域性设置或对系统的区域性数据进行更新,则此方法返回的数据可能会更改。The data returned by this method can change if the current culture changes, the user overrides individual cultural settings, or an update occurs to the system's cultural data.
适用于
GetDateTimeFormats(Char)
将此实例的值转换为指定的标准日期和时间格式说明符支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier.
public:
cli::array <System::String ^> ^ GetDateTimeFormats(char format);
public string[] GetDateTimeFormats (char format);
member this.GetDateTimeFormats : char -> string[]
Public Function GetDateTimeFormats (format As Char) As String()
参数
- format
- Char
标准日期和时间格式字符串。A standard date and time format string.
返回
- String[]
符串数组,其中每个元素都表示此实例的以 format 标准日期和时间格式说明符之一进行格式设置的一个值。A string array where each element is the representation of the value of this instance formatted with the format standard date and time format specifier.
例外
format 不是有效的标准日期和时间格式说明符。format is not a valid standard date and time format specifier character.
示例
下面的示例演示 GetDateTimeFormats(Char) 方法。The following example demonstrates the GetDateTimeFormats(Char) method. 它使用长日期格式说明符 ( "D" ) 为当前区域性显示日期的字符串表示形式。It displays the string representation of a date using the long date format specifier ("D") for the current culture.
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
// Get the long date formats using the current culture.
string [] longJuly28Formats =
july28.GetDateTimeFormats('D');
// Display july28 in all long date formats.
foreach (string format in longJuly28Formats) {
Console.WriteLine(format);
}
// The example displays the following output:
// Tuesday, July 28, 2009
// July 28, 2009
// Tuesday, 28 July, 2009
// 28 July, 2009
Dim july28 As Date = #7/28/2009 5:23:15#
' Get the long date formats using the current culture.
Dim longJuly28Formats() As String = july28.GetDateTimeFormats("D"c)
' Display july28 in all long date formats.
For Each format As String In longJuly28Formats
Console.WriteLine(format)
Next
' The example displays the following output:
' Tuesday, July 28, 2009
' July 28, 2009
' Tuesday, 28 July, 2009
' 28 July, 2009
注解
format参数可以是任何标准日期和时间格式说明符。The format parameter can be any of the standard date and time format specifiers. 其中包括 d、D、f、F、g、G、M (或 M) 、O (或 o) 、R (或 R) 、s、t、T、u、U 和 Y (或 y) 。These include d, D, f, F, g, G, M (or m), O (or o), R (or r), s, t, T, u, U, and Y (or y). 有关详细信息,请参阅 标准日期和时间格式字符串。For more information, see Standard Date and Time Format Strings.
使用当前区域性中的信息设置返回值的每个元素的格式。Each element of the return value is formatted using information from the current culture. 有关当前区域性的区域性特定格式设置信息的详细信息,请参阅 CultureInfo.CurrentCulture 。For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.
重要
由于此方法使用区分区域性的数据,因此不应假定对方法的多个调用将返回相同的数据。Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data. 如果当前区域性发生更改、用户重写单独的区域性设置或对系统的区域性数据进行更新,则此方法返回的数据可能会更改。The data returned by this method can change if the current culture changes, the user overrides individual cultural settings, or an update occurs to the system's cultural data.
适用于
GetDateTimeFormats(IFormatProvider)
将此实例的值转换为标准日期和时间格式说明符和指定的区域性特定格式信息支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the standard date and time format specifiers and the specified culture-specific formatting information.
public:
cli::array <System::String ^> ^ GetDateTimeFormats(IFormatProvider ^ provider);
public string[] GetDateTimeFormats (IFormatProvider provider);
public string[] GetDateTimeFormats (IFormatProvider? provider);
member this.GetDateTimeFormats : IFormatProvider -> string[]
Public Function GetDateTimeFormats (provider As IFormatProvider) As String()
参数
- provider
- IFormatProvider
一个对象,它提供有关此实例的区域性特定格式设置信息。An object that supplies culture-specific formatting information about this instance.
返回
- String[]
字符串数组,其中每个元素都表示此实例的以标准日期和时间格式说明符之一进行格式设置的一个值。A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
示例
下面的示例演示 DateTime.GetDateTimeFormats(IFormatProvider) 方法。The following example demonstrates the DateTime.GetDateTimeFormats(IFormatProvider) method. 它使用 fr-fr 区域性的所有可能标准日期和时间格式显示日期的字符串表示形式。It displays the string representation of a date using all possible standard date and time formats for the fr-FR culture.
DateTime juil28 = DateTime(2009, 7, 28, 5, 23, 15, 16);
IFormatProvider^ culture = gcnew System::Globalization::CultureInfo("fr-FR", true );
// Get the short date formats using the S"fr-FR" culture.
array<String^>^frenchJuly28Formats = juil28.GetDateTimeFormats(culture );
// Print [Out] july28* in all DateTime formats using fr-FR culture.
System::Collections::IEnumerator^ myEnum2 = frenchJuly28Formats->GetEnumerator();
while ( myEnum2->MoveNext() )
{
String^ format = safe_cast<String^>(myEnum2->Current);
System::Console::WriteLine(format );
}
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);
IFormatProvider culture =
new System.Globalization.CultureInfo("fr-FR", true);
// Get the short date formats using the "fr-FR" culture.
string [] frenchJuly28Formats =
july28.GetDateTimeFormats(culture);
// Display july28 in various formats using "fr-FR" culture.
foreach (string format in frenchJuly28Formats) {
Console.WriteLine(format);
}
Dim july28 As New DateTime(2009, 7, 28, 5, 23, 15, 16)
Dim culture As New System.Globalization.CultureInfo("fr-FR", True)
Dim july28Formats As String()
' Get the short date formats using the "fr-FR" culture.
july28Formats = july28.GetDateTimeFormats(culture)
' Print out july28 in various formats using "fr-FR" culture.
For Each format As String In july28Formats
Console.WriteLine(format)
Next
该示例显示以下输出:The example displays the following output:
28/07/2009
28/07/09
28.07.09
28-07-09
2009-07-28
mardi 28 juillet 2009
28 juil. 09
28 juillet 2009
mardi 28 juillet 2009 05:23
mardi 28 juillet 2009 5:23
mardi 28 juillet 2009 05.23
mardi 28 juillet 2009 05 h 23
28 juil. 09 05:23
28 juil. 09 5:23
28 juil. 09 05.23
28 juil. 09 05 h 23
28 juillet 2009 05:23
28 juillet 2009 5:23
28 juillet 2009 05.23
28 juillet 2009 05 h 23
mardi 28 juillet 2009 05:23:15
mardi 28 juillet 2009 5:23:15
mardi 28 juillet 2009 05.23
mardi 28 juillet 2009 05 h 23
28 juil. 09 05:23:15
28 juil. 09 5:23:15
28 juil. 09 05.23
28 juil. 09 05 h 23
28 juillet 2009 05:23:15
28 juillet 2009 5:23:15
28 juillet 2009 05.23
28 juillet 2009 05 h 23
28/07/2009 05:23
28/07/2009 5:23
28/07/2009 05.23
28/07/2009 05 h 23
28/07/09 05:23
28/07/09 5:23
28/07/09 05.23
28/07/09 05 h 23
28.07.09 05:23
28.07.09 5:23
28.07.09 05.23
28.07.09 05 h 23
28-07-09 05:23
28-07-09 5:23
28-07-09 05.23
28-07-09 05 h 23
2009-07-28 05:23
2009-07-28 5:23
2009-07-28 05.23
2009-07-28 05 h 23
28/07/2009 05:23:15
28/07/2009 5:23:15
28/07/2009 05.23
28/07/2009 05 h 23
28/07/09 05:23:15
28/07/09 5:23:15
28/07/09 05.23
28/07/09 05 h 23
28.07.09 05:23:15
28.07.09 5:23:15
28.07.09 05.23
28.07.09 05 h 23
28-07-09 05:23:15
28-07-09 5:23:15
28-07-09 05.23
28-07-09 05 h 23
2009-07-28 05:23:15
2009-07-28 5:23:15
2009-07-28 05.23
2009-07-28 05 h 23
28 juillet
28 juillet
2009-07-28T05:23:15.0160000
2009-07-28T05:23:15.0160000
Tue, 28 Jul 2009 05:23:15 GMT
Tue, 28 Jul 2009 05:23:15 GMT
2009-07-28T05:23:15
05:23
5:23
05.23
05 h 23
05:23:15
5:23:15
05.23
05 h 23
2009-07-28 05:23:15Z
mardi 28 juillet 2009 12:23:15
mardi 28 juillet 2009 12:23:15
mardi 28 juillet 2009 12.23
mardi 28 juillet 2009 12 h 23
28 juil. 09 12:23:15
28 juil. 09 12:23:15
28 juil. 09 12.23
28 juil. 09 12 h 23
28 juillet 2009 12:23:15
28 juillet 2009 12:23:15
28 juillet 2009 12.23
28 juillet 2009 12 h 23
juillet 2009
juillet 2009
注解
方法返回的字符串数组等效于将 DateTime.GetDateTimeFormats(IFormatProvider) 通过单独调用返回的字符串数组 DateTime.GetDateTimeFormats(Char, IFormatProvider) 与 "d"、"d"、"f"、"f"、"g"、"g"、"m"、"o"、"r"、"s"、"t"、"t"、"u"、"u" 和 "y" 标准格式字符串。The string array returned by the DateTime.GetDateTimeFormats(IFormatProvider) method is equivalent to combining the string arrays returned by separate calls to the DateTime.GetDateTimeFormats(Char, IFormatProvider) method with the "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U", and "y" standard format strings. 有关标准格式说明符的详细信息,请参阅 标准日期和时间格式字符串。For more information about standard format specifiers, see Standard Date and Time Format Strings.
返回值的每个元素均使用提供的区域性特定信息进行格式化 provider 。Each element of the return value is formatted using culture-specific information supplied by provider.
重要
由于此方法使用区分区域性的数据,因此不应假定对方法的多个调用将返回相同的数据,除非 provider 是 CultureInfo 表示固定区域性的对象。Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data unless provider is a CultureInfo object that represents the invariant culture. 如果用户重写的单个区域性设置, provider 或如果对系统的区域性数据进行更新,则此方法返回的数据可能会更改 provider 。The data returned by this method can change if the user overrides the individual cultural settings of provider or if an update occurs to the system's cultural data for provider.
适用于
GetDateTimeFormats(Char, IFormatProvider)
将此实例的值转换为指定的标准日期和时间格式说明符和区域性特定格式信息支持的所有字符串表示形式。Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier and culture-specific formatting information.
public:
cli::array <System::String ^> ^ GetDateTimeFormats(char format, IFormatProvider ^ provider);
public string[] GetDateTimeFormats (char format, IFormatProvider provider);
public string[] GetDateTimeFormats (char format, IFormatProvider? provider);
member this.GetDateTimeFormats : char * IFormatProvider -> string[]
Public Function GetDateTimeFormats (format As Char, provider As IFormatProvider) As String()
参数
- format
- Char
标准和时间格式字符串。A date and time format string.
- provider
- IFormatProvider
一个对象,它提供有关此实例的区域性特定格式设置信息。An object that supplies culture-specific formatting information about this instance.
返回
- String[]
字符串数组,其中每个元素都表示此实例的以标准日期和时间格式说明符之一进行格式设置的一个值。A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
例外
format 不是有效的标准日期和时间格式说明符。format is not a valid standard date and time format specifier character.
示例
下面的示例演示 GetDateTimeFormats(Char, IFormatProvider) 方法。The following example demonstrates the GetDateTimeFormats(Char, IFormatProvider) method. 它使用短日期格式说明符来显示日期的字符串表示形式, ( "d" ) 用于 fr-fr 区域性。It displays the string representations of a date using the short date format specifier ("d") for the fr-FR culture.
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
IFormatProvider culture =
new System.Globalization.CultureInfo("fr-FR", true);
// Get the short date formats using the "fr-FR" culture.
string [] frenchJuly28Formats =
july28.GetDateTimeFormats('d', culture);
// Display july28 in short date formats using "fr-FR" culture.
foreach (string format in frenchJuly28Formats) {
Console.WriteLine(format);
}
// The example displays the following output:
// 28/07/2009
// 28/07/09
// 28.07.09
// 28-07-09
// 2009-07-28
Dim july28 As Date = #7/28/2009 5:23:15#
Dim culture As IFormatProvider = New System.Globalization.CultureInfo("fr-FR", True)
' Get the short date formats using the "fr-FR" culture.
Dim frenchJuly28Formats() As String = july28.GetDateTimeFormats("d"c, culture)
' Display july28 in short date formats using "fr-FR" culture.
For Each format As String In frenchJuly28Formats
Console.WriteLine(format)
Next
' The example displays the following output:
' 28/07/2009
' 28/07/09
' 28.07.09
' 28-07-09
' 2009-07-28
注解
Format 参数可以是任何标准日期和时间格式说明符。The format parameter can be any of the standard date and time format specifiers. 其中包括 d、D、f、F、g、G、M (或 M) 、O (或 o) 、R (或 R) 、s、t、T、u、U 和 Y (或 y) 。These include d, D, f, F, g, G, M (or m), O (or o), R (or r), s, t, T, u, U, and Y (or y). 有关详细信息,请参阅 标准日期和时间格式字符串。For more information, see Standard Date and Time Format Strings.
返回值的每个元素均使用提供的区域性特定信息进行格式化 provider 。Each element of the return value is formatted using culture-specific information supplied by provider.
重要
由于此方法使用区分区域性的数据,因此不应假定对方法的多个调用将返回相同的数据,除非 provider 是 CultureInfo 表示固定区域性的对象。Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data unless provider is a CultureInfo object that represents the invariant culture. 如果用户重写的单个区域性设置, provider 或如果对系统的区域性数据进行更新,则此方法返回的数据可能会更改 provider 。The data returned by this method can change if the user overrides the individual cultural settings of provider or if an update occurs to the system's cultural data for provider.