How to get the start and end times of a day

后端 未结 10 696
无人及你
无人及你 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:17

    I think we're doing it wrong. There is no such thing as the end of the day. AddTick(-1) only works under the convention that there are no time intervals smaller than a tick. Which is implementation dependent. Admittedly the question comes with a reference implementation, namely the .Net Framework DateTime class, but still we should take this as a clue that the function we really want is not EndOfDay() but StartOfNextDay()

    public static DateTime StartOfNextDay(this DateTime date)
    {
        return date.Date.AddDays(1);
    }
    

提交回复
热议问题