Strip seconds from datetime

前端 未结 8 1428
死守一世寂寞
死守一世寂寞 2021-01-04 05:41

I want to trip/remove seconds from date time. I checked some solution but showing solution using format string like

DateTime datetime = DateTime.UtcNow;
         


        
8条回答
  •  耶瑟儿~
    2021-01-04 05:43

    How about this rather elegant solution?

    new DateTime(DateTime.UtcNow.Ticks / 600000000 * 600000000)
    

    ... which will also strip any milli/micro/nanoseconds.

提交回复
热议问题