ECMAScript(简称 ES)作为 JavaScript 的标准,每年都会推出新的特性,不断优化我们的开发体验,分享几个实用的新特性。
Temporal API - 现代化的日期时间处理
// 旧写法
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1; // 注意 month 是从 0 开始的
const day = now.getDate();
// ES2024写法
const now = Temporal.Now.plainDateTimeISO();
const year = now.year;
const month = now.month;
const day = now.day;
...大约 3 分钟