SyntaxStudy
Sign Up
JavaScript Beginner 4 min read

Creating Date Objects

Date Constructor

Create dates with new Date() using different arguments: no args for now, a timestamp, an ISO string, or year/month/day components.

Example
new Date()                     // Current time
new Date(1718000000000)        // From timestamp (ms)
new Date("2024-06-15")        // ISO date string (UTC midnight)
new Date("2024-06-15T10:30:00") // ISO with time (local time)

// Note: months are 0-indexed!
new Date(2024, 5, 15)         // June 15, 2024 (month 5 = June)

// Get timestamp
Date.now()                    // Current time as ms
new Date("2024-01-01").getTime()
Pro Tip

Months are 0-indexed in the Date constructor — January is 0, December is 11. Always double-check month values.