Note to readers: Several commenters have pointed out some problems in this answer (related particularly to the first suggestion). (读者注意:一些评论者指出了此答案中的一些问题(特别是与第一个建议有关)。) Refer to the comments section for more information. (有关更多信息,请参见评论部分。)
DateTime.UtcNow.ToString("yyyy-MM-ddTHH\:mm\:ss.fffffffzzz");
This gives you a date similar to 2008-09-22T13:57:31.2311892-04:00 . (这给您一个类似于2008-09-22T13:57:31.2311892-04:00的日期 。)
Another way is: (另一种方法是:)
DateTime.UtcNow.ToString("o");
which gives you 2008-09-22T14:01:54.9571247Z (这给你2008-09-22T14:01:54.9571247Z)
To get the specified format, you can use: (要获取指定的格式,可以使用:)
DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
DateTime Formatting Options (日期时间格式选项)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…