C# DateTime去掉时分秒几种方法

C# DateTime去掉时分秒几种方法

DateTime now = DateTime.Parse(“2015/01/23 13:50:00”);
Console.WriteLine(now.Date); //去掉时分秒,返回DateTime
Console.WriteLine(now.ToShortDateString()); //去掉时分秒,返回string
Console.WriteLine(now.ToString(“d”)); //去掉时分秒,返回string
Console.WriteLine(now.ToString(“yyyy-MM-dd”)); //去掉时分秒,返回string
Console.WriteLine(DateTime.Today); //当天日期无时分秒,返回DateTime
输出内容:
2015/1/23 0:00:00
2015/1/23
2015/1/23
2015-01-23
2015/1/23 0:00:00

你可能感兴趣的:(C#,c#)