给定一个DateTime对象,我怎么获得字符串格式的ISO 8601日期? [英] Given a DateTime object, how do I get a ISO 8601 date in string format?
本文介绍了给定一个DateTime对象,我怎么获得字符串格式的ISO 8601日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设:
DateTime.UtcNow
我如何得到一个字符串,它重新presents在 ISO相同的值8601 兼容的格式?
需要注意的是ISO 8601定义了许多类似的格式:我在找的具体格式为:
YYYY-MM-DDTHH:MM:SSZ
解决方案
DateTime.UtcNow.ToString(YYYY-MM-DDTHH \\\\:\\\\毫米:ss.fffffffzzz) ;
这为您提供了类似于日期 2008-09-22T13:57:31.2311892-04:00
另一种方法是:
DateTime.UtcNow.ToString(O);
这给您 2008-09-22T14:01:54.9571247Z
要获得指定的格式,你可以使用:
DateTime.UtcNow.ToString(YYYY-MM-DDTHH:MM:SSZ)
Given:
DateTime.UtcNow
How do I get a string which represents the same value in an ISO 8601 compliant format?
Note that ISO 8601 defines a number of similar formats: The specific format I am looking for is:
yyyy-MM-ddTHH:mm:ssZ
解决方案
DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz");
This gives you a date similar to 2008-09-22T13:57:31.2311892-04:00.
Another way is:
DateTime.UtcNow.ToString("o");
which gives you 2008-09-22T14:01:54.9571247Z
To get the specified format, you can use:
DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
这篇关于给定一个DateTime对象,我怎么获得字符串格式的ISO 8601日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文