JavaScript new Date
Description
The new Date()
constructor creates a new Date object.
Syntax
new Date(date)
Parameters
Parameter | Description |
date | Optional. A timestamp (milliseconds) or a date time string. |
Return Value
Type | Description |
Date | A new Date object. |
Related Pages:
More Examples
There are five ways of instantiating (creating) a new Date:
Example
Create a new date object with the current date and time:
// Create a Date
const time = new Date();
Try it Yourself »
Example
Create a new date using an ISO notation:
const time = new Date(dateString);
Try it Yourself »
Example
Create a new date using milliseconds from Jan 1, 1970:
const time = new Date(milliseconds);
Try it Yourself »
Example
Using new Date(7 numbers) creates a date object with the specified date and time:
const time = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Try it Yourself »
Browser Support
new Date()
is an ECMAScript1 (JavaScriopt 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |