Remove hours:seconds:milliseconds in DateTime object

前端 未结 9 2129
忘了有多久
忘了有多久 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:32

    If you want to remove hours, seconds, milliseconds (remove as reset to 0) from a DateTime object without converting to a string, you can use the Date property.

    // Get date-only portion of date, without its time.
    var date = DateTime.Now.Date;
    

    The example below uses the Date property to extract the date component of a DateTime value with its time component set to zero (or 0:00:00, or midnight).

    msdn

提交回复
热议问题