简体   繁体   中英

parse unrecognized timestamp format

How do I get the time-stamp to look like this "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 . It is recommended format for XML date fields, also have very nice property of being sortable with string comparison.

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.

To convert DateTime to that format use "u" or "O"/"o" Standard Date and Time Format Strings .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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