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
廣告