[英]How to convert string date to following date format dd/MM/yyyy t:m:s in C#
I need to convert date format from string to dd/MM/yyyy tt:mm:ss
in C# for example convert 我需要将日期格式从字符串转换为C#中的
dd/MM/yyyy tt:mm:ss
,例如convert
string = "2015-07-21T23:00:00.000Z"
to 至
{21/07/2015 00:00:00}
I would parse it to DateTime
with DateTimeStyles.RoundtripKind
enumeration since it is ISO 8601 format then use it's Date
property to set it's time part to midnight. 我将使用
DateTimeStyles.RoundtripKind
枚举将其解析为DateTime
,因为它是ISO 8601格式,然后使用其Date
属性将其时间部分设置为午夜。
var dt = DateTime.Parse("2015-07-21T23:00:00.000Z", null, DateTimeStyles.RoundtripKind);
Console.WriteLine(dt.Date.ToString("dd'/'MM'/'yyyy HH:mm:ss")); // 21/07/2015 00:00:00
Here a demonstration
. 这里有
demonstration
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.