C# 中的完全日期短時間 (“f”) 格式說明符


完全日期短時間標準格式說明符表示長時間日期(“D”)和短時間(“t”)模式的組合。

使用DateTime來設定日期。

DateTime myDate = new DateTime(2018, 8, 29, 1, 10, 0);

現在,使用以下格式說明符(“f”)-

myDate.ToString("f", CultureInfo.CreateSpecificCulture("en-US"))

以下是示例 -

示例

 即時演示

using System;
using System.Globalization;
class Demo {
   static void Main() {
      DateTime myDate = new DateTime(2018, 8, 29, 1, 10, 0);
      Console.WriteLine(myDate.ToString("f",CultureInfo.CreateSpecificCulture("en-US")));
   }
}

輸出

Wednesday, August 29, 2018 1:10 AM

更新於: 2020 年 6 月 23 日

142 次瀏覽

啟動您的 職業生涯

透過完成課程獲得認證

開始
廣告