c# DateTime常用用法


參考:http://sqlyuju.com/c-datetime-hh-hh-qubie.html

https://www.cnblogs.com/xiongxiaobai/p/5282827.html 

 

        DateTime now = DateTime.Now;
       //當前時間 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;

 

 

 

注意:

MM是月份

mm是分鍾

hh是12進制小時

HH是24進制小時


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM