how to give format DateTime.Date?

前端 未结 7 792
滥情空心
滥情空心 2021-01-29 10:47

DateTime dt = DateTime.Now dt.Date is created to 31.10.2012 00:00:00 .it is created to dd.mm.yyyy format but i need dd/mm/yyyy. Can i use: return new DateTime(d.Year, d.Month

7条回答
  •  遇见更好的自我
    2021-01-29 11:25

    The DateTime struct doesn't store any formatting information internally. If you want to output the DateTime instance as a formatted string, you just need to call ToString() with the proper format string:

    var date = DateTime.Now;
    var formattedString = date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
    

    If you need more information on exactly which specifiers to use in your format string, check out:

    MSDN - Custom Date and Time Format Strings

提交回复
热议问题