DateTime.GetDateTimeFormats Metoda

Definicja

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez standardowe specyfikatory formatu daty i godziny.

Przeciążenia

GetDateTimeFormats()

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez standardowe specyfikatory formatu daty i godziny.

GetDateTimeFormats(Char)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez określony standardowy specyfikator formatu daty i godziny.

GetDateTimeFormats(IFormatProvider)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez standardowe specyfikatory formatu daty i godziny oraz określone informacje dotyczące formatowania specyficzne dla kultury.

GetDateTimeFormats(Char, IFormatProvider)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez określony standardowy specyfikator formatu daty i godziny oraz informacje o formatowaniu specyficznym dla kultury.

Uwagi

Ważne

Nie należy zakładać, że wiele wywołań przeciążeń GetDateTimeFormats zwróci identyczne dane. W zależności od określonego przeciążenia dane zwrócone przez tę metodę mogą ulec zmianie, jeśli bieżąca kultura ulegnie zmianie, użytkownik zastąpi poszczególne ustawienia kulturowe lub aktualizacja wystąpi w danych kulturowych systemu.

GetDateTimeFormats()

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez standardowe specyfikatory formatu daty i godziny.

public:
 cli::array <System::String ^> ^ GetDateTimeFormats();
public string[] GetDateTimeFormats ();
member this.GetDateTimeFormats : unit -> string[]
Public Function GetDateTimeFormats () As String()

Zwraca

String[]

Tablica ciągów, w której każdy element jest reprezentacją wartości tego wystąpienia sformatowanej przy użyciu jednego ze standardowych specyfikatorów formatu daty i godziny.

Przykłady

W poniższym przykładzie pokazano metodę DateTime.GetDateTimeFormats() . Wyświetla on reprezentację ciągu daty przy użyciu wszystkich możliwych standardowych formatów daty i godziny w bieżącej kulturze komputera, co w tym przypadku jest 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

W przykładzie zostaną wyświetlone następujące dane wyjściowe:

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

Uwagi

Tablica ciągów zwrócona przez DateTime.GetDateTimeFormats() metodę jest równoważna połączeniu tablic ciągów zwracanych przez oddzielne wywołania DateTime.GetDateTimeFormats(Char) metody z ciągami "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U" i "y" standardowych ciągów. Aby uzyskać więcej informacji na temat standardowych specyfikatorów formatu, zobacz Standardowe ciągi formatu daty i godziny.

Każdy element wartości zwracanej jest sformatowany przy użyciu informacji z bieżącej kultury. Aby uzyskać więcej informacji na temat formatowania specyficznego dla kultury dla bieżącej kultury, zobacz CultureInfo.CurrentCulture.

Ważne

Ponieważ ta metoda używa danych wrażliwych na kulturę, nie należy zakładać, że wiele wywołań metody zwróci identyczne dane. Dane zwrócone przez tę metodę mogą ulec zmianie, jeśli bieżąca kultura ulegnie zmianie, użytkownik zastąpi poszczególne ustawienia kulturowe lub aktualizacja nastąpi w danych kulturowych systemu.

Zobacz też

Dotyczy

GetDateTimeFormats(Char)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez określony standardowy specyfikator formatu daty i godziny.

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

Parametry

format
Char

Standardowy ciąg formatu daty i godziny.

Zwraca

String[]

Tablica ciągów, w której każdy element jest reprezentacją wartości tego wystąpienia sformatowanej za pomocą specyfikatora formatu daty i godziny standardowej format .

Wyjątki

format nie jest prawidłowym standardowym znakiem specyfikatora formatu daty i godziny.

Przykłady

W poniższym przykładzie pokazano metodę GetDateTimeFormats(Char) . Wyświetla on reprezentację ciągu daty przy użyciu specyfikatora formatu daty długiej ("D") dla bieżącej kultury.

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

Uwagi

Parametr format może być dowolnym ze standardowych specyfikatorów formatu daty i godziny. Należą do nich d, D, f, F, g, G, M (lub m), O (lub o), R (lub r), s, t, T, u, U i Y (lub y). Aby uzyskać więcej informacji, zobacz Standardowe ciągi formatu daty i godziny.

Każdy element wartości zwracanej jest sformatowany przy użyciu informacji z bieżącej kultury. Aby uzyskać więcej informacji na temat formatowania specyficznego dla kultury dla bieżącej kultury, zobacz CultureInfo.CurrentCulture.

Ważne

Ponieważ ta metoda używa danych wrażliwych na kulturę, nie należy zakładać, że wiele wywołań metody zwróci identyczne dane. Dane zwrócone przez tę metodę mogą ulec zmianie, jeśli bieżąca kultura ulegnie zmianie, użytkownik zastąpi poszczególne ustawienia kulturowe lub aktualizacja nastąpi w danych kulturowych systemu.

Zobacz też

Dotyczy

GetDateTimeFormats(IFormatProvider)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez standardowe specyfikatory formatu daty i godziny oraz określone informacje dotyczące formatowania specyficzne dla kultury.

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

Parametry

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu tego wystąpienia specyficzne dla kultury.

Zwraca

String[]

Tablica ciągów, w której każdy element jest reprezentacją wartości tego wystąpienia sformatowanej przy użyciu jednego ze standardowych specyfikatorów formatu daty i godziny.

Przykłady

W poniższym przykładzie pokazano metodę DateTime.GetDateTimeFormats(IFormatProvider) . Wyświetla on reprezentację ciągu daty przy użyciu wszystkich możliwych standardowych formatów daty i godziny dla kultury fr-FR.

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

W przykładzie zostaną wyświetlone następujące dane wyjściowe:

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

Uwagi

Tablica ciągów zwrócona przez DateTime.GetDateTimeFormats(IFormatProvider) metodę jest równoważna połączeniu tablic ciągów zwracanych przez oddzielne wywołania DateTime.GetDateTimeFormats(Char, IFormatProvider) metody z ciągami "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U" i "y" standardowych ciągów. Aby uzyskać więcej informacji na temat standardowych specyfikatorów formatu, zobacz Standardowe ciągi formatu daty i godziny.

Każdy element wartości zwracanej jest sformatowany przy użyciu informacji specyficznych dla kultury dostarczonych przez providerprogram .

Ważne

Ponieważ ta metoda używa danych wrażliwych na kulturę, nie należy zakładać, że wiele wywołań metody zwróci identyczne dane, chyba że provider jest obiektem reprezentującym CultureInfo niezmienną kulturę. Dane zwrócone przez tę metodę mogą ulec zmianie, jeśli użytkownik zastąpi poszczególne ustawienia provider kulturowe lub jeśli aktualizacja wystąpi w danych kulturowych systemu dla providerprogramu .

Zobacz też

Dotyczy

GetDateTimeFormats(Char, IFormatProvider)

Konwertuje wartość tego wystąpienia na wszystkie reprezentacje ciągów obsługiwane przez określony standardowy specyfikator formatu daty i godziny oraz informacje o formatowaniu specyficznym dla kultury.

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

Parametry

format
Char

Ciąg formatu daty i godziny.

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu tego wystąpienia specyficzne dla kultury.

Zwraca

String[]

Tablica ciągów, w której każdy element jest reprezentacją wartości tego wystąpienia sformatowanej przy użyciu jednego ze standardowych specyfikatorów formatu daty i godziny.

Wyjątki

format nie jest prawidłowym standardowym znakiem specyfikatora formatu daty i godziny.

Przykłady

W poniższym przykładzie pokazano metodę GetDateTimeFormats(Char, IFormatProvider) . Wyświetla reprezentacje ciągów daty przy użyciu specyfikatora formatu daty krótkiej ("d") dla kultury fr-FR.

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

Uwagi

Parametr formatu może być dowolnym ze standardowych specyfikatorów formatu daty i godziny. Należą do nich d, D, f, F, g, G, M (lub m), O (lub o), R (lub r), s, t, T, u, U i Y (lub y). Aby uzyskać więcej informacji, zobacz Standardowe ciągi formatu daty i godziny.

Każdy element wartości zwracanej jest sformatowany przy użyciu informacji specyficznych dla kultury dostarczonych przez providerprogram .

Ważne

Ponieważ ta metoda używa danych wrażliwych na kulturę, nie należy zakładać, że wiele wywołań metody zwróci identyczne dane, chyba że provider jest obiektem reprezentującym CultureInfo niezmienną kulturę. Dane zwrócone przez tę metodę mogą ulec zmianie, jeśli użytkownik zastąpi poszczególne ustawienia provider kulturowe lub jeśli aktualizacja wystąpi w danych kulturowych systemu dla providerprogramu .

Zobacz też

Dotyczy