短日期 ("d") 格式說明符
"d" 格式說明符表示自定義日期和時間格式字串。
格式字串由區域性的 DateTimeFormatInfo.ShortDatePattern 屬性來定義。
自定義格式字串為 −
MM/dd/yyyy
示例
using System; using System.Globalization; class Demo { static void Main() { DateTime myDate = new DateTime(2018,9, 09); Console.WriteLine(myDate.ToString("d", DateTimeFormatInfo.InvariantInfo)); Console.WriteLine(myDate.ToString("d", CultureInfo.CreateSpecificCulture("en-US"))); } }
輸出
09/09/2018 9/9/2018
廣告