DateTime Round Up and Down

前端 未结 5 1857
面向向阳花
面向向阳花 2021-02-07 12:58

Ive been looking for a proper rounding mechanism but nothing I find seems to be exactly what I need.

I need to round up and round down seperately and I also need to acco

5条回答
  •  长发绾君心
    2021-02-07 13:34

    Here is a fast way to truncate (round down)

    var now = DateTime.Now;
    var nowTicks = now.Ticks;
    
    //removing the nanoseconds, miliseconds, and seconds from the nowTicks
    var lastMinute = new DateTime(nowTicks - (nowTicks % (1000*1000*10*60)));
    

提交回复
热议问题