new Date() → Creates a Date object with the current date & time.new Date(timestamp) → Creates a Date from a milliseconds timestamp (since 1970-01-01 UTC) or ISO8601 time string.new Date(year, month, day?, hour?, min?, sec?, ms?) → Creates a date from individual values.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).
.getFullYear() → Returns the year..getMonth() → Returns the month (0-11)..getDate() → Returns the day of the month..getDay() → Returns the day of the week (0 = Sunday)..getHours(), .getMinutes(), .getSeconds(), .getMilliseconds() → Returns time 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
.setFullYear(year), .setMonth(month), .setDate(day).setHours(hours), .setMinutes(min), .setSeconds(sec), .setMilliseconds(ms)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).
.getTime() → Returns the timestamp (milliseconds since 1970-01-01 UTC).