DateTime 数字型
System.DateTime currentTime=new System.DateTime();
//当前时间
Console.WriteLine(now);
//年月日 - 时分秒(为0)
Console.WriteLine(now.Date.ToString());
//年月日 - 时分
Console.WriteLine(now.ToString("yyyy-MM-dd hh:mm"));
//年月日
Console.WriteLine(now.ToString("yyyy-MM-dd"));
//时分
Console.WriteLine(now.ToString("HH:mm:ss"));
//增加一天
DateTime afterNow = now.AddDays(1);
Console.WriteLine(afterNow);
//减去一天
DateTime beforeNow = now.AddDays(-1);
Console.WriteLine(beforeNow);
//A-B
DateTime startDate = now.Date;
DateTime endDate = now.AddDays(1).Date;
注意:
YYYY是年
MM是月份
mm是分钟
hh是12进制小时
HH是24进制小时