Difference between System.DateTime.Now and System.DateTime.Today

后端 未结 8 1119
悲哀的现实
悲哀的现实 2020-11-28 19:23

Can anyone explain the difference between System.DateTime.Now and System.DateTime.Today in C#.NET? Pros and cons of each if possible.

8条回答
  •  Happy的楠姐
    2020-11-28 20:13

    The DateTime.Now property returns the current date and time, for example 2011-07-01 10:09.45310.

    The DateTime.Today property returns the current date with the time compnents set to zero, for example 2011-07-01 00:00.00000.

    The DateTime.Today property actually is implemented to return DateTime.Now.Date:

    public static DateTime Today {
      get {
        DateTime now = DateTime.Now;
        return now.Date;
      }
    }
    

提交回复
热议问题