C# 中的可排序 (“s”) 格式說明符


可排序標準格式說明符表示自定義日期和時間格式字串。

格式字串由 DateTimeFormatInfo.SortableDateTimePattern 屬性定義。

自定義格式字串。

yyyy'-'MM'-'dd'T'HH':'mm':'ss

示例

 線上演示

using System;
class Demo {
   static void Main() {
      DateTime date = new DateTime(2018, 9, 5, 2, 12, 40);
      Console.WriteLine(date.ToString("s"));
   }
}

輸出

2018-09-05T02:12:40

更新於:2020 年 06 月 23 日

402 次瀏覽

開啟您的職業生涯

完成課程獲得認證

開始
廣告