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
参考资料
[1].标准日期和时间格式字符串:https://msdn.microsoft.com/zh-cn/library/az4se3k1.aspx
[2].自定义日期和时间格式字符串:https://msdn.microsoft.com/zh-cn/library/8kb3ddd4.aspx
评论(0)
暂无评论。