如何从ISO 8601格式创建一个.NET日期时间 [英] How to create a .NET DateTime from ISO 8601 format
本文介绍了如何从ISO 8601格式创建一个.NET日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现如何把日期时间为一个 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.
这篇关于如何从ISO 8601格式创建一个.NET日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文