Breyta

Deila með


DateTime.GetDateTimeFormats Method

Definition

Converts the value of this instance to all the string representations supported by the standard date and time format specifiers.

Overloads

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.

Remarks

Important

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()

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

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()

Returns

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.

Examples

The following example demonstrates the DateTime.GetDateTimeFormats() method. 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 );
}
let july28 = DateTime(2009, 7, 28, 5, 23, 15, 16)

let july28Formats = july28.GetDateTimeFormats()

// Print out july28 in all DateTime formats using the default culture.
for format in july28Formats do
    printfn $"{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

Remarks

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. For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.

Important

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.

See also

Applies to

GetDateTimeFormats(Char)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

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()

Parameters

format
Char

A standard date and time format string.

Returns

String[]

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.

Exceptions

format is not a valid standard date and time format specifier character.

Examples

The following example demonstrates the GetDateTimeFormats(Char) method. It displays the string representation of a date using the long date format specifier ("D") for the current culture.

let july28 = DateTime(2009, 7, 28, 5, 23, 15)

// Get the long date formats using the current culture.
let longJuly28Formats =
    july28.GetDateTimeFormats 'D'

// Display july28 in all long date formats.
for format in longJuly28Formats do
    printfn $"{format}"

// The example displays the following output:
//       Tuesday, July 28, 2009
//       July 28, 2009
//       Tuesday, 28 July, 2009
//       28 July, 2009
  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

Remarks

The format parameter can be any of the standard date and time format specifiers. 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. For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.

Important

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.

See also

Applies to

GetDateTimeFormats(IFormatProvider)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

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()

Parameters

provider
IFormatProvider

An object that supplies culture-specific formatting information about this instance.

Returns

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.

Examples

The following example demonstrates the DateTime.GetDateTimeFormats(IFormatProvider) method. 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 );
}
let july28 = DateTime(2009, 7, 28, 5, 23, 15, 16)

let culture =
    System.Globalization.CultureInfo("fr-FR", true)

// Get the short date formats using the "fr-FR" culture.
let frenchJuly28Formats =
    july28.GetDateTimeFormats culture

// Display july28 in various formats using "fr-FR" culture.
for format in frenchJuly28Formats do
    printfn $"{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

Remarks

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.

Each element of the return value is formatted using culture-specific information supplied by provider.

Important

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. 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.

See also

Applies to

GetDateTimeFormats(Char, IFormatProvider)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

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()

Parameters

format
Char

A date and time format string.

provider
IFormatProvider

An object that supplies culture-specific formatting information about this instance.

Returns

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.

Exceptions

format is not a valid standard date and time format specifier character.

Examples

The following example demonstrates the GetDateTimeFormats(Char, IFormatProvider) method. It displays the string representations of a date using the short date format specifier ("d") for the fr-FR culture.

let july28 = DateTime(2009, 7, 28, 5, 23, 15)

let culture =
    System.Globalization.CultureInfo("fr-FR", true)

// Get the short date formats using the "fr-FR" culture.
let frenchJuly28Formats =
    july28.GetDateTimeFormats('d', culture)

// Display july28 in short date formats using "fr-FR" culture.
for format in frenchJuly28Formats do
    printfn $"{format}"

// The example displays the following output:
//       28/07/2009
//       28/07/09
//       28.07.09
//       28-07-09
//       2009-07-28
  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

Remarks

The format parameter can be any of the standard date and time format specifiers. 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 culture-specific information supplied by provider.

Important

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. 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.

See also

Applies to