JS: Date Constructor
new Date(args)→ Return a date object.Date()→ Return a string. (don't use this.)
new Date()
new Date()-
Return a date object that represents the current datetime when this function is called.
console.log(new Date()); // 2026-02-03T22:36:36.626Z console.log((new Date()).toString()); // Tue Feb 03 2026 14:36:36 GMT-0800 (Pacific Standard Time)
new Date(year, month …)
new Date(year, month)-
Return a date object of given local year month.
🛑 WARNING: January is 0.
// note: January is 0 console.log((new Date(2026, 0))); // 2026-01-01T08:00:00.000Z new Date(year, month, day, hours, minutes, seconds, ms)-
The year, month are required, other parameters are optional.
🛑 WARNING: January is 0.
// note: January is 0 console.log((new Date(2026, 0, 1))); // 2026-01-01T08:00:00.000Z
The arguments are interpreted as local time. (If you want args to be UTC, use Date.UTC . )
Argument format:
- year → 4 digits integer.
- month → 0 to 11. January is 0.
- day → 1 to 31.
- hours → 0 to 23.
- minutes → 0 to 59.
- seconds → 0 to 59.
- ms → 0 to 999.
new Date(milliseconds)
new Date(milliseconds)-
Return a date object that represents the datetime of milliseconds since 01 January, 1970 UTC.
console.log(new Date(0)); // 1970-01-01T00:00:00.000Z
This milliseconds is how JavaScript represents datetime internally.
new Date(string)
new Date(ISO_string)-
Return a date object that represents the datetime in ISO_string.
console.log(new Date("2016-04-08T15:48:22.000Z")); // 2016-04-08T15:48:22.000Z For the format of ISO_string, see Date.parse
Date() ❌
Date()-
- Return a string that represents the current time when this function is called.
- 🛑 WARNING: Arguments to
Date()are ignored.
🟢 TIP: don't use this. if you want a date in string format, use
(new Date()).toISOString().console.log(Date()); // Wed Feb 04 2026 16:34:40 GMT-0800 (Pacific Standard Time) console.assert(typeof (Date()) === "string"); console.assert(Date() === (new Date()).toString()); // arg to Date() are ignored console.assert(Date(1999) === Date());