共用方式為


DateTimeFormatInfo.UniversalSortableDateTimePattern 屬性

定義

取得自訂格式字串,以取得由 ISO 8601 所定義的國際標準、可排序日期和時間字串。

public:
 property System::String ^ UniversalSortableDateTimePattern { System::String ^ get(); };
public string UniversalSortableDateTimePattern { get; }
member this.UniversalSortableDateTimePattern : string
Public ReadOnly Property UniversalSortableDateTimePattern As String

屬性值

國際標準、可排序日期和時間字串的自訂格式字串。

範例

下列範例會顯示幾個文化特性的 值 UniversalSortableDateTimePattern

using namespace System;
using namespace System::Globalization;
void PrintPattern( String^ myCulture )
{
   CultureInfo^ MyCI = gcnew CultureInfo( myCulture,false );
   DateTimeFormatInfo^ myDTFI = MyCI->DateTimeFormat;
   Console::WriteLine( " {0} {1}", myCulture, myDTFI->UniversalSortableDateTimePattern );
}

int main()
{
   
   // Displays the values of the pattern properties.
   Console::WriteLine( " CULTURE    PROPERTY VALUE" );
   PrintPattern( "en-US" );
   PrintPattern( "ja-JP" );
   PrintPattern( "fr-FR" );
}

/*
This code produces the following output.

CULTURE    PROPERTY VALUE
en-US     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
ja-JP     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
fr-FR     yyyy'-'MM'-'dd HH':'mm':'ss'Z'

*/
using System;
using System.Globalization;

public class SamplesDTFI  {

   public static void Main()  {

      // Displays the values of the pattern properties.
      Console.WriteLine( " CULTURE    PROPERTY VALUE" );
      PrintPattern( "en-US" );
      PrintPattern( "ja-JP" );
      PrintPattern( "fr-FR" );
   }

   public static void PrintPattern( String myCulture )  {

      DateTimeFormatInfo myDTFI = new CultureInfo( myCulture, false ).DateTimeFormat;
      Console.WriteLine( "  {0}     {1}", myCulture, myDTFI.UniversalSortableDateTimePattern );
   }
}

/*
This code produces the following output.

 CULTURE    PROPERTY VALUE
  en-US     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
  ja-JP     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
  fr-FR     yyyy'-'MM'-'dd HH':'mm':'ss'Z'

*/
Imports System.Globalization

Public Class SamplesDTFI

   Public Shared Sub Main()

      ' Displays the values of the pattern properties.
      Console.WriteLine(" CULTURE    PROPERTY VALUE")
      PrintPattern("en-US")
      PrintPattern("ja-JP")
      PrintPattern("fr-FR")

   End Sub

   Public Shared Sub PrintPattern(myCulture As [String])

      Dim myDTFI As DateTimeFormatInfo = New CultureInfo(myCulture, False).DateTimeFormat
      Console.WriteLine("  {0}     {1}", myCulture, myDTFI.UniversalSortableDateTimePattern)

   End Sub

End Class

'This code produces the following output.
'
' CULTURE    PROPERTY VALUE
'  en-US     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
'  ja-JP     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
'  fr-FR     yyyy'-'MM'-'dd HH':'mm':'ss'Z'
'

備註

屬性 UniversalSortableDateTimePattern 會定義日期字串的格式,這些字串是由呼叫 DateTime.ToStringDateTimeOffset.ToString 方法所傳回,以及提供 「u」 標準格式字串的複合格式字串所傳回。 其可用來以可排序順序顯示日期和時間,並在結尾使用通用時間指示項 「Z」。。 格式是可排序的,因為它使用年份、月、日、小時、分鐘和秒的前置零。 不論文化特性或格式提供者為何,自定義格式字串 (“yyyy'-'MM'-'dd HH':'mm':'ss'Z'”) 相同。

屬性所 UniversalSortableDateTimePattern 傳回的格式字串會反映已定義的標準,而且屬性是唯讀的。 因此,不論文化特性為何,它一律相同。 自訂格式字串為 "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"。

適用於

另請參閱