短日期 ("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

更新於: 2020 年 6 月 23 日

229 瀏覽量

啟動你的 職業

透過課程認證

開始
廣告