C# convert DateTime from one format to another

后端 未结 3 1726
鱼传尺愫
鱼传尺愫 2021-01-22 13:31

I thought this would be a really simple, and i\'ve tried to google it and I keep getting the exception String was not recognized as a valid DateTime.

This i

3条回答
  •  旧巷少年郎
    2021-01-22 14:15

    Your string appears to be in format of "Xml-serialized". So it is the job of XmlConvert.

    string sample = "2013-10-21T14:10:49";
    string converted = XmlConvert.ToDateTime(sample, XmlDateTimeSerializationMode.Unspecified)
         .ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
    

提交回复
热议问题