c#获取凌晨时间


一、获取今天凌晨时间:

  方法一:

DateTime today1 = DateTime.Now.Date;
Console.WriteLine(today1);
// 输出格式   2021/5/26 0:00:00

  方法二:

DateTime now = DateTime.Now;
DateTime today2 = new DateTime(now.Year, now.Month, now.Day);
Console.WriteLine(today2);
// 输出格式   2021/5/26 0:00:00

 

二,获取其它时间的凌晨时间:

  例如获取一个月前的凌晨时间

DateTime now = DateTime.Now.AddMonths(-1);
DateTime today2 = new DateTime(now.Year, now.Month, now.Day);
Console.WriteLine(today2);
// 输出格式   2021/4/26 0:00:00

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM