How can I specify the latest time of day with DateTime

后端 未结 12 1095
不思量自难忘°
不思量自难忘° 2020-12-14 14:03

I am using a System.DateTime object to allow a user to select a date range. The user is only able to select a date (not time) using a third party calendar so I

12条回答
  •  太阳男子
    2020-12-14 15:09

    To get the last instant for today:

    DateTime d = new DateTime(Now.Year, Now.Month, Now.Day);
    d = d.AddDays(1);
    d = d.AddTicks(-1);
    

    In response to your edit, here's what I would do:

    DateTime start = new DateTime(Now.Year, Now.Month, Now.Day);
    DateTime end = start.AddDays(1).AddTicks(-1);
    
    // Or - just use end = start.AddDays(1), and use a < for comparison
    

提交回复
热议问题