DateTimeFormatInfo.ShortTimePattern 属性

定义

获取或设置短时间值的自定义格式字符串。

public:
 property System::String ^ ShortTimePattern { System::String ^ get(); void set(System::String ^ value); };
public string ShortTimePattern { get; set; }
member this.ShortTimePattern : string with get, set
Public Property ShortTimePattern As String

属性值

短时间值的自定义格式字符串。

例外

该属性设置为 null

设置了该属性,但 DateTimeFormatInfo 对象为只读。

示例

以下示例显示几个区域性的 的值 ShortTimePattern

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->ShortTimePattern );
}

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     h:mm tt
ja-JP     H:mm
fr-FR     HH:mm

*/
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.ShortTimePattern );
   }
}

/*
This code produces the following output.

 CULTURE    PROPERTY VALUE
  en-US     h:mm tt
  ja-JP     H:mm
  fr-FR     HH:mm

*/
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.ShortTimePattern)

   End Sub

End Class

'This code produces the following output.
'
' CULTURE    PROPERTY VALUE
'  en-US     h:mm tt
'  ja-JP     H:mm
'  fr-FR     HH:mm
'

注解

属性 ShortTimePattern 定义通过调用 DateTime.ToStringDateTimeOffset.ToString 方法以及提供“t”标准格式字符串的复合格式字符串返回的日期字符串的区域性特定格式。

建议将短时间模式中的时间分隔符设置为确切的字符串,而不是使用时间分隔符占位符。 例如,若要获取模式 h-mm-ss,请将短时间模式设置为“h-mm-ss”。

适用于

另请参阅