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

适用于

另请参阅