how to give format DateTime.Date?

前端 未结 7 659
滥情空心
滥情空心 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:07

    DateTime, numeric types and most other types do not store their values in a formatted way. Rather they store their data using a binary representation. If you want to display this data to the user, you must convert it to a string. This conversion involves formatting the data.

    string formattedDate = DateTime.Now.ToString("dd/MM/yyyy",
                                                 CultureInfo.InvariantCulture);
    

    Or

    Console.WriteLine("Date = {0:dd/MM/yyyy}", DateTime.Now);
    

    Console.WriteLine converts the date into a string in order to write it to the console.

提交回复
热议问题