问题

我见过这么多不同的JSON日期格式的标准:

"\"\\/Date(1335205592410)\\/\""         .NET JavaScriptSerializer
"\"\\/Date(1335205592410-0500)\\/\""    .NET DataContractJsonSerializer
"2012-04-23T18:25:43.511Z"              JavaScript built-in JSON object
"2012-04-21T18:25:43-05:00"             ISO 8601

哪一个是正确的?还是最好?这是有什么标准吗?



解决方法

JSON 本身指定应如何表示日期,但是JavaScript.

使用 日期 toJSON 方法:

2012-04-23T18:25:43.511Z

原因如下:

  1. It's human readable but also succinct

  2. It sorts correctly

  3. It includes fractional seconds, which can help re-establish chronology

  4. It conforms to ISO 8601

  5. ISO 8601 has been well-established internationally for more than a decade

  6. ISO 8601 is endorsed by W3C, RFC3339, and XKCD

,每个写的日期库都可以理解”自1970年以来的毫秒数”.所以为了方便携带,ThiefMaster是对的.




相关问题推荐