C# 中的短時間 (“t”) 格式說明符


短時間格式說明符表示自定義日期和時間格式字串。

它是由當前 DateTimeFormatInfo.ShortTimePattern 屬性定義的。

例如,自定義格式字串為 −

HH:mm

示例

 即時演示

using System;
using System.Globalization;
class Demo {
   static void Main() {
      DateTime date = new DateTime(2018, 5, 4, 10, 12, 10);
      Console.WriteLine(date.ToString("t", CultureInfo.CreateSpecificCulture("en-us")));
   }
}

輸出

10:12 AM

更新於: 23-Jun-2020

368 次瀏覽

開啟你的 事業

完成課程即可獲得認證

開始
廣告