For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/stage/4/proposal-intl-datetime-style.md.
  • 简体中文
  • DateTimeFormat dateStyle & timeStyle S4

    中文标题:DateTimeFormat 的 dateStyle 与 timeStyle

    提案概览
    提案速览

    本提案为 Intl.DateTimeFormat 添加了 dateStyletimeStyle 两个选项,以紧凑的方式请求特定于语言环境且具有给定长度的日期和时间格式。它为显式指定各个日期/时间组件提供了一种更简单的替代方案。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    Intl.DateTimeFormat API 规范中的 dateStyle 与 timeStyle 选项 [草案]

    本提案为 Intl.DateTimeFormat 添加两个选项:dateStyletimeStyle。这些选项提供了一种紧凑的方式,用于请求特定于语言环境的、适合不同长度的日期和时间格式。

    状态

    当前阶段:

    • 第 4 阶段

    规范文本:

    作者

    • Zibi Braniecki (@zbraniecki)

    审阅者

    • Frank Tang (@FrankYFTang)
    • Nathan Hammond (@nathanhammond)

    参考资料

    本提案基于 CLDR 日期/时间模式:

    用法

    let o = new Intl.DateTimeFormat("en" , {
      timeStyle: "short"
    });
    console.log(o.format(Date.now())); // "13:31"
    
    let o = new Intl.DateTimeFormat("en" , {
      dateStyle: "short"
    });
    console.log(o.format(Date.now())); // "21.03.2012"
    
    let o = new Intl.DateTimeFormat("en" , {
      timeStyle: "medium",
      dateStyle: "short"
    });
    console.log(o.format(Date.now())); // "21.03.2012, 13:31"

    渲染规范

    npm install
    npm run build
    open index.html

    反向链接