Creating Dates

console.log(new Date()); // Current date & time
console.log(new Date(1700000000000)); // From timestamp
console.log(new Date(2025, 0, 1, 12, 30, 45)); // 2025-01-01 12:30:45

Months are zero-based (0 = January, 11 = December).

Getting Date Components

const date = new Date();
console.log(date.getFullYear()); // 2025
console.log(date.getMonth()); // 0 (January)
console.log(date.getDate()); // 1
console.log(date.getDay()); // 3 (Wednesday)
console.log(date.getHours(), date.getMinutes()); // e.g., 14 30

Setting Date Components

const date = new Date();
date.setFullYear(2030);
date.setMonth(5); // June
date.setDate(15);
console.log(date); // Updated date

If a value is out of range, it auto-adjusts (setDate(32) moves to the next month).

Timestamps & Differences