DateTime.GetDateTimeFormats 方法

定義

將此實例的值轉換為標準日期與時間格式規範符所支援的所有字串表示。

多載

名稱 Description
GetDateTimeFormats()

將此實例的值轉換為標準日期與時間格式規範符所支援的所有字串表示。

GetDateTimeFormats(Char)

將此實例的值轉換為指定標準日期與時間格式指定符所支援的所有字串表示。

GetDateTimeFormats(IFormatProvider)

將此實例的值轉換為標準日期與時間格式指定符及特定文化格式資訊所支援的所有字串表示。

GetDateTimeFormats(Char, IFormatProvider)

將此實例的值轉換為指定標準日期與時間格式指定符及文化特定格式資訊所支援的所有字串表示。

備註

Important

你不應該假設多次呼叫超 GetDateTimeFormats 載會回傳相同的資料。 根據特定的超載情況,當當前文化改變、使用者覆寫個別文化設定,或系統文化資料更新時,此方法回傳的資料可能會改變。

GetDateTimeFormats()

來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs

將此實例的值轉換為標準日期與時間格式規範符所支援的所有字串表示。

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

傳回

String[]

一個字串陣列,每個元素代表該實例的值,並以標準日期與時間格式指定符之一格式化。

範例

以下範例示範此 DateTime.GetDateTimeFormats() 方法。 它會以電腦目前文化中所有可能的標準日期和時間格式,顯示日期的字串表示,在此情況下的文化是 en-US。

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

範例顯示以下輸出:

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」標準格式字串結合。 欲了解更多標準格式指定符的資訊,請參閱 標準日期與時間格式字串

回傳值的每個元素皆以當前文化的資訊進行格式化。 欲了解更多關於當前文化特定格式資訊的資訊,請參見 CultureInfo.CurrentCulture

Important

由於此方法使用文化敏感資料,不應假設多次呼叫該方法會回傳相同的資料。 此方法回傳的資料可能會因當前文化改變、使用者覆寫個別文化設定,或系統文化資料更新而改變。

另請參閱

適用於

GetDateTimeFormats(Char)

來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs

將此實例的值轉換為指定標準日期與時間格式指定符所支援的所有字串表示。

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

標準的日期與時間格式字串。

傳回

String[]

一個字串陣列,每個元素代表該實例的值,並以 format 標準的日期與時間格式指定符格式化。

例外狀況

format 不是有效的標準日期與時間格式指定字元。

範例

以下範例示範此 GetDateTimeFormats(Char) 方法。 它使用當前文化的長日期格式指定符(「D」)來顯示日期的字串表示。

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

備註

format參數可以是任何標準的日期與時間格式指定符。 這些包括 d、D、f、F、g、G、M(或 m)、O(或 o)、R(或 r)、s、t、T、u、U 和 Y(或 y)。 欲了解更多資訊,請參閱 標準日期與時間格式字串

回傳值的每個元素皆以當前文化的資訊進行格式化。 欲了解更多關於當前文化特定格式資訊的資訊,請參見 CultureInfo.CurrentCulture

Important

由於此方法使用文化敏感資料,不應假設多次呼叫該方法會回傳相同的資料。 此方法回傳的資料可能會因當前文化改變、使用者覆寫個別文化設定,或系統文化資料更新而改變。

另請參閱

適用於

GetDateTimeFormats(IFormatProvider)

來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs

將此實例的值轉換為標準日期與時間格式指定符及特定文化格式資訊所支援的所有字串表示。

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

一個提供此實例特定文化格式資訊的物件。

傳回

String[]

一個字串陣列,每個元素代表該實例的值,並以標準日期與時間格式指定符之一格式化。

範例

以下範例示範此 DateTime.GetDateTimeFormats(IFormatProvider) 方法。 它以所有可能的標準日期和時間格式顯示日期的字串表示,適用於 fr-FR 文化。

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

範例顯示以下輸出:

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」標準格式字串結合。 欲了解更多標準格式指定符的資訊,請參閱 標準日期與時間格式字串

回傳值的每個元素皆以文化特定資訊 provider格式化。

Important

由於此方法使用文化敏感資料,不應假設多次呼叫該方法會回傳相同資料,除非 providerCultureInfo 代表不變文化的物件。 若使用者覆寫個別 provider 的文化設定,或系統的文化資料 provider發生更新,該方法回傳的資料可能會改變。

另請參閱

適用於

GetDateTimeFormats(Char, IFormatProvider)

來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs
來源:
DateTime.cs

將此實例的值轉換為指定標準日期與時間格式指定符及文化特定格式資訊所支援的所有字串表示。

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

一個日期和時間格式的字串。

provider
IFormatProvider

一個提供此實例特定文化格式資訊的物件。

傳回

String[]

一個字串陣列,每個元素代表該實例的值,並以標準日期與時間格式指定符之一格式化。

例外狀況

format 不是有效的標準日期與時間格式指定字元。

範例

以下範例示範此 GetDateTimeFormats(Char, IFormatProvider) 方法。 它使用短日期格式指定符(「d」)來顯示 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

備註

格式參數可以是任何標準的日期與時間格式指定符。 這些包括 d、D、f、F、g、G、M(或 m)、O(或 o)、R(或 r)、s、t、T、u、U 和 Y(或 y)。 欲了解更多資訊,請參閱 標準日期與時間格式字串

回傳值的每個元素皆以文化特定資訊 provider格式化。

Important

由於此方法使用文化敏感資料,不應假設多次呼叫該方法會回傳相同資料,除非 providerCultureInfo 代表不變文化的物件。 若使用者覆寫個別 provider 的文化設定,或系統的文化資料 provider發生更新,該方法回傳的資料可能會改變。

另請參閱

適用於