• 时间本地化开发规范


    时间本地化指的是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

  • 相关阅读:
    1018hw
    Navicat连接Oracle数据库:Oracle library is not loaded 解决方案
    第6章 循环神经网络
    wav文件碎片多删除后恢复案例
    OpenDataV低代码平台增加自定义属性编辑
    虹科教您 | 可实现带宽计量和延迟计算的时间敏感网络测试工具RELY-TSN-LAB操作指南与基本功能测试
    比nestjs更优雅的ioc:跨模块访问资源
    ant-design版本升级从V4到V5
    链的解构主义:一览 9 大模块化公链
    MVP 聚技站|.NET C# 系列(二):创建并运行简单的 C# 控制台应用程序
  • 原文地址:https://blog.csdn.net/babyblue_963/article/details/133499415