C#通用日期短时间(“ g”)格式说明符
生成日期短时间格式说明符是短日期(“d”)和短时间(“t”)模式的组合,并用空格分隔。
使用DateTime设置日期。
DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);
现在,使用(“g”)格式说明符。
dt.ToString("g", DateTimeFormatInfo.InvariantInfo));示例
using System;
using System.Globalization;
class Demo {
static void Main() {
DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);
Console.WriteLine(dt.ToString("g", DateTimeFormatInfo.InvariantInfo));
Console.WriteLine(dt.ToString("g", CultureInfo.CreateSpecificCulture("en-us")));
}
}输出结果
10/02/2018 07:59 10/2/2018 7:59 AM
热门推荐
10 学生节祝福语大全简短
11 冬至婆婆的祝福语简短
12 群里祝福语简短幽默
13 直播生孩子祝福语简短
14 拜年啦祝福语大全简短
15 妈妈给宝贝祝福语简短
16 牛年女神节祝福语简短
17 龙年简短祝福语有哪些
18 诗词文案祝福语简短精辟