Date
7 methodsRepresents a single moment in time (milliseconds since Unix epoch).
date.getDate()Return the day of the month (1..31) in local time.
Returns
number
Example
javascript
new Date('2024-06-15').getDate() // 15date.getMonth()Return the month (0..11, where 0 = January) in local time.
Returns
number
Example
javascript
new Date('2024-06-15').getMonth() // 5 (June)date.getFullYear()Return the 4-digit year in local time.
Returns
number
Example
javascript
new Date('2024-06-15').getFullYear() // 2024date.toISOString()Return the date in ISO 8601 format (UTC): YYYY-MM-DDTHH:mm:ss.sssZ.
Returns
string
Example
javascript
new Date('2024-06-15T12:00:00Z').toISOString()
// '2024-06-15T12:00:00.000Z'date.toLocaleDateString(locale?, options?)Return a string with a language-sensitive representation of the date.
Parameters
| Name | Type | Description |
|---|---|---|
| locale | string | string[] | BCP 47 locale tag (e.g. 'en-US'). |
| options | object | Formatting options. |
Returns
string
Example
javascript
new Date(2024, 5, 15).toLocaleDateString('en-US')
// '6/15/2024'
new Date(2024, 5, 15).toLocaleDateString('zh-CN')
// '2024/6/15'Date.now()Static method. Return the number of milliseconds elapsed since Unix epoch.
Returns
number
Example
javascript
Date.now() // e.g. 1718452800000
const start = Date.now();
// ... do work ...
console.log(Date.now() - start, 'ms');Date.parse(dateString)Static method. Parse a date string and return milliseconds since epoch, or NaN.
Parameters
| Name | Type | Description |
|---|---|---|
| dateString | string | Date string (ISO 8601 recommended). |
Returns
number
Example
javascript
Date.parse('2024-06-15T00:00:00Z') // 1718409600000
Date.parse('not a date') // NaN