Remove hours:seconds:milliseconds in DateTime object

前端 未结 9 2201
忘了有多久
忘了有多久 2021-01-17 09:43

I\'m trying to create a string from the DateTime object which yields the format mm:dd:yyyy.

Conventionally the DateTime object comes as

9条回答
  •  庸人自扰
    2021-01-17 10:14

    Easy way, probably not the best but

    DateTime dt = new DateTime();
    dt = DateTime.Now;
    string sdate = dt.ToShortDateString();
    dt = DateTime.Parse(sdate);
    

    Or for short

    var dt = DateTime.Parse(DateTime.Now.ToShortDateString());
    

提交回复
热议问题