简体   繁体   English

解析无法识别的时间戳格式

[英]parse unrecognized timestamp format

How do I get the time-stamp to look like this "2013-06-07T00:04:48Z"? 如何获得类似“ 2013-06-07T00:04:48Z”的时间戳? I can't even decode it to get what time it is, what standard does it supposed to be? 我什至无法解码它的时间,它应该是什么标准?

It is ISO8601 date format, natively supported by DateTime . 它是ISO8601日期格式DateTime本身支持。 It is recommended format for XML date fields, also have very nice property of being sortable with string comparison. 推荐使用XML日期字段格式,它还具有可以通过字符串比较进行排序的很好的属性。

Sample: 样品:

var date = DateTime.Parse("2013-06-07T00:04:48Z");

Note that Z denotes UTC time-zone and parsed value will be converted to your local timezone. 请注意, Z表示UTC时区,解析后的值将转换为您的本地时区。

To convert DateTime to that format use "u" or "O"/"o" Standard Date and Time Format Strings . 要将DateTime转换为该格式,请使用“ u”“ O” /“ o” 标准日期和时间格式字符串

Sample: 样品:

 var isoDate = DateTime.Now.ToString("u"); // 2013-07-19 20:15:10Z

Note that T is optional in the format, "O" option gives you string with local timezone instead of UTC. 请注意, T在格式中是可选的,“ O”选项为您提供具有本地时区而不是UTC的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM