DateTimeFormatInfo.LongTimePattern 屬性

定義

取得或設定完整時間值的自訂格式字串。

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

屬性值

完整時間值的格式模式。

例外狀況

此屬性設定為 null

正在設定屬性,而且 DateTimeFormatInfo 物件為唯讀。

範例

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

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

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

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

/*
This code produces the following output.

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

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

   End Sub

End Class

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

備註

屬性 LongTimePattern 會定義呼叫 DateTime.ToStringDateTimeOffset.ToString 方法以及提供 「T」 標準格式字串之複合格式字串所傳回之日期字串的文化特性特定格式。

我們建議您將長時間模式中的時間分隔符號設定為確切字串,而不是使用時間分隔符號預留位置。 例如,若要取得 h-mm-ss 模式,請將完整日期模式設定為 「h-mm-ss」。

適用於

另請參閱