JavaScript new Date()
- Previous Page
- Next Page
- Go Up One Level JavaScript Date Reference Manual
Definition and usage
new Date()
The constructor is used to create a new Date object.
Instance
There are five ways to instantiate (create) a new Date object:
Example 1
// Create a date object const time = new Date();
Example 2
Create a new date using ISO notation:
const time = new Date(dateString);
Example 3
Create a new date from an existing date:
const time2 = new Date(time1);
Example 4
Create a new date using the number of milliseconds since January 1, 1970:
const time = new Date(milliseconds);
Example 5
Create a Date object with a specified date and time using new Date(7 numbers):
const time = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Syntax
new Date(date)
Parameter
Parameter | Description |
---|---|
date | Optional. Timestamp (in milliseconds) or date-time string. |
Return value
Type | Description |
---|---|
Date | A new Date object. |
Browser Support
new Date()
Is an ECMAScript1 (JavaScript 1997) feature.
All Browsers Support:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
Related Pages
- Previous Page
- Next Page
- Go Up One Level JavaScript Date Reference Manual