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

后端 未结 30 3766
醉话见心
醉话见心 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:43

    The Date property will return the date at midnight.

    One option could be to get the individual values (day/month/year) separately and store it in the type you want.

    var dateAndTime = DateTime.Now; 
    int year = dateAndTime.Year;
    int month = dateAndTime.Month;
    int day = dateAndTime.Day;
    
    string.Format("{0}/{1}/{2}", month, day, year);
    

提交回复
热议问题