How to remove time portion of date in C# in DateTime object only?

后端 未结 30 3741
醉话见心
醉话见心 2020-11-22 09:08

I need to remove time portion of date time or probably have the date in following format in object form not in the form of string.

         


        
30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 09:52

    Use the Date property:

    var dateAndTime = DateTime.Now;
    var date = dateAndTime.Date;
    

    The date variable will contain the date, the time part will be 00:00:00.

提交回复
热议问题