我发现如何把日期时间为一个 ISO 8601 的格式,但没有就如何做反向在C#。
I've found how to turn a DateTime into an ISO 8601 format, but nothing on how to do the reverse in C#.
我有'2010-08-20T15:00:00Z',我希望把它变成一个DateTime对象
I have '2010-08-20T15:00:00Z', and I want to turn it into a DateTime object.
我可以分隔字符串自己的部分,但是这似乎是很多工作的东西,已经是一个国际标准。
I could separate the parts of the string myself, but that seems like a lot of work for something that is already an international standard.
该解决方案使用了 DateTimeStyles的枚举,并且它也可以以Z。
This solution makes use of the DateTimeStyles enumeration, and it also works with Z.
DateTime d2= DateTime.Parse("2010-08-20T15:00:00Z", null, System.Globalization.DateTimeStyles.RoundtripKind);
这将打印解决方案完美。
This prints the solution perfectly.