What is the quot;rightquot; JSON date format?(什么是“权利?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.
您应该使用 Date 的 toJSON 方法:
You should use the format emitted by Date's toJSON method:
2012-04-23T18:25:43.511Z
原因如下:
它既可读又简洁
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 的认可,RFC3339 和 XKCD
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日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是“权利"?JSON日期格式?
基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
