閱讀英文

共用方式為


DateTimeFormatInfo.LongTimePattern 屬性

定義

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

public string LongTimePattern { get; set; }

屬性值

完整時間值的格式模式。

例外狀況

此屬性設定為 null

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

範例

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

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

*/

備註

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

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

適用於

另請參閱