生成XML的日期时间格式 [英] Generate datetime format for XML
问题描述
我正尝试为cXML生成时间戳,如下所示。 C#中有任何函数可用于将日期时间格式化为:2011-06-09T16:37:17 + 16:37
I'm trying to generate timestamp for cXML as shown below. Is there any function in C# which I can use to format date time to: 2011-06-09T16:37:17+16:37
eg
<cXML payloadID="accountsuser@bla.com"
timestamp="2011-06-09T16:37:17+16:37">
推荐答案
使用 o格式说明符-了解有关此内容MSDN上标准日期和时间格式字符串文档中的一个。
Use the "o" format specifier - read about this one in the standard Date and Time format strings documentation on MSDN.
此说明符的模式反映了已定义的标准(ISO 8601)。
The pattern for this specifier reflects a defined standard (ISO 8601).
并且:
6/15 / 2009 1:45:30 PM-> 2009-06-15T13:45:30.0900000
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000
string formatted = DateTime.Now.ToString("o");
如果这不是您想要的,则需要使用自定义格式字符串-我相信您需要这样做,因为偏移量不是标准的。
If this is not what you want, you will need to use a custom format string - I believe you will need to do this, as the offset is not standard.
string formatted = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssK");
这篇关于生成XML的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!