Strip seconds from datetime

前端 未结 8 1420
死守一世寂寞
死守一世寂寞 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:46

    DateTime time = DateTime.Now;
    string timestring = time.ToString("g");
    

    ToString("g") will convert DateTime to string and remove seconds.

    Output: 03/29/2018 11:11 PM

提交回复
热议问题