V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
daijinming
V2EX  ›  程序员

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

  •  
  •   daijinming · 2018-08-29 14:17:37 +08:00 · 2364 次点击
    这是一个创建于 2072 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    8 条回复    2018-08-29 16:34:57 +08:00
    qiyuey
        1
    qiyuey  
       2018-08-29 14:19:23 +08:00
    calming
        2
    calming  
       2018-08-29 14:56:14 +08:00
    最简单的解决方案 T 和 Z 用“ ” replace 就完事了
    laike9m
        3
    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
        4
    zhengxiaowai  
       2018-08-29 15:52:52 +08:00
    T 就是个分隔符别搭理他,现在一般也用空格代替。
    yanaraika
        5
    yanaraika  
       2018-08-29 15:54:05 +08:00
    如果提供接口的话,不要改,遵循 ISO8601 的来。让客户端 toLocaleDateString()去
    amazonGo
        6
    amazonGo  
       2018-08-29 16:02:49 +08:00
    用 String 或者 Long 类型替代
    UnknownR
        7
    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
        8
    metrxqin  
       2018-08-29 16:34:57 +08:00
    推荐使用 Timestamp 时间戳便于传输和运算,仅当需要展示时才转成字符串。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2476 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:29 · PVG 21:29 · LAX 06:29 · JFK 09:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.