一、Intl.DateTimeFormat 核心概念
Intl.DateTimeFormat 是 ES6 新增的原生国际化 API,专门用于语言敏感的日期和时间格式化,由浏览器原生实现,无需引入第三方库,是前端处理多语言日期格式化的首选方案。
1.1 基本语法
new Intl.DateTimeFormat(locales, options)
locales:字符串 / 字符串数组,指定语言 / 地区(如 zh-CN、en-US、ja-JP),支持 BCP 47 语言标签。
options:配置对象,控制日期 / 时间的显示格式(可选)。
1.2 核心参数(options)详解
基础参数
日期时间组件参数
格式参数
二、代码示例
2.1 基础用法(默认格式)
// 当前时间,默认语言(浏览器语言),默认格式
const date = new Date(2026, 0, 8, 14, 30, 5); // 2026-01-08 14:30:05
const formatter = new Intl.DateTimeFormat();
console.log(formatter.format(date)); // 输出(zh-CN 环境):2026/1/8
2.2 指定语言和基础日期格式
const date = new Date(2026, 0, 8); // 中文(完整格式)
const cnFormatter = new Intl.DateTimeFormat('zh-CN', {year:, :, :, :});
.(cnFormatter.(date));
enFormatter = .(, {:, :, :, :});
.(enFormatter.(date));


