共用方式為


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」。。

適用於

另請參閱