在.NET中将ISO 8601字符串解析为DateTime? [英] Parsing ISO 8601 string to DateTime in .NET?
本文介绍了在.NET中将ISO 8601字符串解析为DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,2009-10-08 08:22:02Z,它位于 ISO 8601 格式。
I have a string, "2009-10-08 08:22:02Z", which is in ISO 8601 format.
如何使用DateTime解析此格式?
How do I use DateTime to parse this format?
推荐答案
string txt= "2009-10-08 08:22:02Z";
DateTime output = DateTime.ParseExact(txt, "u", System.Globalization.CultureInfo.InvariantCulture);
DateTime类支持这个格式的u的标准格式字符串
The DateTime class supports the standard format string of u for this format
我认为对于ISO格式(使用T分隔符),请使用s而不是u。或使用:
I think for the ISO format (with the T separator), use "s" instead of "u". Or use:
string txt= "2009-10-08 08:22:02Z";
DateTime output = DateTime.ParseExact(txt, new string[] {"s", "u"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
支持两种格式。
这篇关于在.NET中将ISO 8601字符串解析为DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文