我正在尝试为cXML生成时间戳,如下所示。 C#中有什么函数可以用来将日期时间格式化为:2011-06-09T16:37:17 + 16:37
例如
<cXML payloadID="accountsuser@bla.com"
timestamp="2011-06-09T16:37:17+16:37">
最佳答案
使用“o”格式说明符-在MSDN上的standard Date and Time format strings文档中阅读有关此说明符。
和:
string formatted = DateTime.Now.ToString("o");
如果这不是您想要的,则需要使用custom format string-我相信您将需要这样做,因为偏移量不是标准的。
string formatted = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssK");