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'”。

适用于

另请参阅