本文介绍了如何从ISO 8601格式创建.NET DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现如何将DateTime转换为格式,但无关于如何在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.
推荐答案
这个解决方案利用了枚举,它也适用于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);
完美打印解决方案。
这篇关于如何从ISO 8601格式创建.NET DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!