Dates and Internationalization
Represent instants safely and format dates, numbers, and lists for different locales.
A JavaScript Date represents an instant as milliseconds from the Unix epoch. Time-zone and calendar formatting belong at the display boundary.
Parse explicit input
dates.js
const published = new Date("2026-08-13T16:00:00Z");
if (Number.isNaN(published.getTime())) throw new TypeError("Invalid date");
console.log(published.toISOString());
Use ISO 8601 with an explicit offset or Z. Ambiguous date-only or locale-formatted strings can be interpreted differently than expected.
Format for a locale
format.js
const date = new Intl.DateTimeFormat("en-US", {
dateStyle: "long",
timeStyle: "short",
timeZone: "America/New_York",
}).format(published);
const duration = new Intl.NumberFormat("zh-CN").format(112);
const list = new Intl.ListFormat("en", { type: "conjunction" }).format(["HTML", "CSS", "JavaScript"]);
Keep this
Store instants in an unambiguous format, validate parsing, and use Intl for human-readable output.
学习位置已保存在此设备上。