日期类型的字段为什么序列化的时候会有个 T(例如 2011-07-14T19:43:37),有什么讲究吗

2018-08-29 14:17:37 +08:00
 daijinming

日期类型的字段为什么序列化的时候会有个 T (例如 2011-07-14T19:43:37 ),有什么讲究吗?在开发接口的时候,客户端开发人员收到这样的日期数据总要找来问问,怎么回事,能不能去掉?

2380 次点击
所在节点    程序员
8 条回复
qiyuey
2018-08-29 14:19:23 +08:00
calming
2018-08-29 14:56:14 +08:00
最简单的解决方案 T 和 Z 用“ ” replace 就完事了
laike9m
2018-08-29 15:01:11 +08:00
https://stackoverflow.com/questions/29281935/what-exactly-does-the-t-and-z-mean-in-timestamp

> The T doesn't really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time.
The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
zhengxiaowai
2018-08-29 15:52:52 +08:00
T 就是个分隔符别搭理他,现在一般也用空格代替。
yanaraika
2018-08-29 15:54:05 +08:00
如果提供接口的话,不要改,遵循 ISO8601 的来。让客户端 toLocaleDateString()去
amazonGo
2018-08-29 16:02:49 +08:00
用 String 或者 Long 类型替代
UnknownR
2018-08-29 16:17:25 +08:00
T 是 time separator,一般来说默认拿到的都是当前时区的时间,转成 UTC 的话会在末尾加上 Z,大部分都属于系统级的 feature,算是通俗规范定义,硬要拿掉也无所谓

It is in the form of yyyyMMddTHHmmssffffZ (case-sensitive, using a 4-digit year, 2-digit month, 2-digit day, the letter "T" as a time separator, 2-digit hour, 2-digit minute, 2-digit second, 4-digit millisecond, and the letter "Z" as the UTC indicator). An example of results when you use this format is 20150302T0840539947Z
metrxqin
2018-08-29 16:34:57 +08:00
推荐使用 Timestamp 时间戳便于传输和运算,仅当需要展示时才转成字符串。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/484245

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX