How to get the start and end times of a day

后端 未结 10 732
无人及你
无人及你 2020-12-24 00:29

In my C# app, I pass a string variable that is of format yyyymmdd-yyyymmdd that represents a from and to date. I want to get the start and end times for these dates respecti

10条回答
  •  执笔经年
    2020-12-24 01:14

    I am surprised to see how an incorrect answer received so many upvotes:

    Wrong value

    The correct version would be as follows:

    public static DateTime StartOfDay(this DateTime theDate)
    {
        return theDate.Date;
    }
    
    public static DateTime EndOfDay(this DateTime theDate)
    {
        return theDate.Date.AddDays(1).AddTicks(-1);
    }
    

提交回复
热议问题