Strip seconds from datetime

前端 未结 8 1429
死守一世寂寞
死守一世寂寞 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条回答
  •  萌比男神i
    2021-01-04 06:00

    You can do

    DateTime dt = DateTime.Now;
    dt = dt.AddSeconds(-dt.Second);
    

    to set the seconds to 0.

提交回复
热议问题