• 时间本地化开发规范


    时间本地化指的是IT业务系统供不同国家、地区的用户使用时,用户访问页面看到的时间要和日常的使用习惯一致,同时保证用户可以正确理解时间的含意。

    从实现代价最低、实现效果最优的角度,可以制订如下开发规范:

    • UTC时间,格式如下
      • 长整型,即从1970年1月1日0时0分0秒到现在的毫秒数。
      • 字符串,即YYYY-MM-DDThh:mm:ssTZD,例如1997-07-16T19:20:30.45Z。
    • 本地化时间格式,格式如下
      • 未启用夏令时,YYYY-MM-DDThh:mm:ss.s[+|-]+hh:mm,例如1997-07-16T19:20:30+01:00。
      • 启用夏令时,YYYY-MM-DDThh:mm:ss.s[+|-]+hh:mm DST,例如1997-07-16T19:20:30+01:00 DST。
    • 使用UTC格式存储时间。
    • 系统内部各组件交互时,使用UTC时间。
    • 系统对外提供API接口时,使用UTC时间。
    • 系统提供给前端的接口,使用用户本地化时间。
    • 允许用户自定义本地时区、夏令时。用户修改相关配置时,不影响系统的正常运行。
    • 系统所在服务器,允许指定时区和夏令时。修改相关配置时,不影响系统的正常运行。

    参考资料

    时间,UTC,时区,夏令时。

    时间格式

    Formats
    Different standards may need different levels of granularity in the date and time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions.

    The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the “T” appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.

    Year:
    YYYY (eg 1997)
    Year and month:
    YYYY-MM (eg 1997-07)
    Complete date:
    YYYY-MM-DD (eg 1997-07-16)
    Complete date plus hours and minutes:
    YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
    Complete date plus hours, minutes and seconds:
    YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
    Complete date plus hours, minutes, seconds and a decimal fraction of a
    second
    YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
    where:

    YYYY = four-digit year
    MM   = two-digit month (01=January, etc.)
    DD   = two-digit day of month (01 through 31)
    hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
    mm   = two digits of minute (00 through 59)
    ss   = two digits of second (00 through 59)
    s    = one or more digits representing a decimal fraction of a second
    TZD  = time zone designator (Z or +hh:mm or -hh:mm)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    This profile does not specify how many digits may be used to represent the decimal fraction of a second. An adopting standard that permits fractions of a second must specify both the minimum number of digits (a number greater than or equal to one) and the maximum number of digits (the maximum may be stated to be “unlimited”).

    This profile defines two ways of handling time zone offsets:

    Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator (“Z”).
    Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of “+hh:mm” indicates that the date/time uses a local time zone which is “hh” hours and “mm” minutes ahead of UTC. A time zone offset of “-hh:mm” indicates that the date/time uses a local time zone which is “hh” hours and “mm” minutes behind UTC.
    A standard referencing this profile should permit one or both of these ways of handling time zone offsets.


    Examples
    1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.

    1994-11-05T13:15:30Z corresponds to the same instant.

    ISO 8601

    时区

    Time zone

    夏令时

    Daylight saving time

  • 相关阅读:
    帆软报表之填报报表
    .NET Web入门到高级路线(新版本)
    2022夏暑假每日一题(七)
    媲美有线操作,支持4KHz响应和无线充电的游戏鼠标,雷柏VT3S上手
    windbg使用教程
    【高项笔记】No.1 信息系统与信息化
    Vue3-ref、reactive函数的watch
    【算能全国产AI盒子】基于BM1688&CV186AH+FPGA智能物联工作站,支持差异化泛AI视觉产品定制
    Java面试题200+大全(合适各级Java人员)
    详细介绍Springcloud,Springcloud alibaba,dubbo等微服务框架,以及nacos和feign
  • 原文地址:https://blog.csdn.net/babyblue_963/article/details/133499415