How can I specify the latest time of day with DateTime

后端 未结 12 1094
不思量自难忘°
不思量自难忘° 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:08

    Based on the other answers I created this convenient extension method:

    public static class DateTimeExtensions
    {
        public static DateTime EndOfDay(this DateTime dateTime)
        {
            return dateTime.Date.AddDays(1).AddTicks(-1);
        }
    }
    

提交回复
热议问题