A concise reference for every Date operation you'll need — parsing, formatting, arithmetic, comparison, and timezone handling.
new Date() // Now
new Date("2025-02-22T14:30:00Z") // From ISO string (UTC)
new Date(1708560000 * 1000) // From Unix timestamp
new Date(2025, 1, 22) // Feb 22, 2025 LOCAL time (month is 0-indexed)
const d = new Date("2025-02-22T14:30:45.123Z");
d.getUTCFullYear() // 2025
d.getUTCMonth() // 1 (0-indexed! January=0)
d.getUTCDate() // 22
d.getUTCHours() // 14
d.getTime() // 1708560000000 (ms since epoch)
const d = new Date("2025-02-22T14:30:00Z");
d.toISOString() // "2025-02-22T14:30:00.000Z"
d.toLocaleDateString("en-US") // "2/22/2025"
d.toLocaleDateString("de-DE") // "22.2.2025"
// Custom format with Intl
new Intl.DateTimeFormat("en-US", {
year: "numeric", month: "long", day: "numeric"
}).format(d); // 'February 22, 2025'
const d = new Date("2025-02-22T00:00:00Z");
const ms = d.getTime();
// Add 7 days
new Date(ms + 7 * 24 * 60 * 60 * 1000);
// Difference in days
const diff = (dateA - dateB) / (1000 * 60 * 60 * 24);
const a = new Date("2025-01-01");
const b = new Date("2025-06-01");
a < b // true
a - b // negative (ms difference)
// Sort array of dates
dates.sort((a, b) => new Date(a.date) - new Date(b.date));