Get the system date and split day, month and year

后端 未结 5 940
猫巷女王i
猫巷女王i 2020-12-06 18:18

My system date format is dd-MM-yyyy(20-10-2012) and I\'m getting the date and using separator to split the date, month and year. I need to convert date format (dd/MM/yyyy) w

5条回答
  •  不知归路
    2020-12-06 19:14

    Without opening an IDE to check my brain works properly for syntax at this time of day...

    If you simply want the date in a particular format you can use DateTime's .ToString(string format). There are a number of examples of standard and custom formatting strings if you follow that link.

    So

    DateTime _date = DateTime.Now;
    var _dateString = _date.ToString("dd/MM/yyyy");
    

    would give you the date as a string in the format you request.

提交回复
热议问题