什么是“权利"?JSON 日期格式? [英] What is the "right" JSON date format?

查看:31
本文介绍了什么是“权利"?JSON 日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've seen so many different standards for the JSON date format:

""\/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

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

Which one is the right one? Or best? Is there any sort of standard on this?

推荐答案

JSON 本身 指定日期的表示方式,但 JavaScript 可以.

JSON itself does not specify how dates should be represented, but JavaScript does.

应该使用DatetoJSON 方法:

You should use the format emitted by Date's toJSON method:

2012-04-23T18:25:43.511Z

原因如下:

  1. 它是人类可读的,但也很简洁

  1. It's human readable but also succinct

排序正确

它包括小数秒,可以帮助重新建立年表

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

它符合 ISO 8601

ISO 8601 在国际上已有十多年的历史

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

ISO 8601 得到 W3C 的认可,RFC3339XKCD

ISO 8601 is endorsed by W3C, RFC3339, and XKCD

话虽如此,曾经编写的每个日期库都可以理解自 1970 年以来的毫秒数".因此,为了便于携带,ThiefMaster 是正确的.

That being said, every date library ever written can understand "milliseconds since 1970". So for easy portability, ThiefMaster is right.

这篇关于什么是“权利"?JSON 日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆