The new Date() Constructor
In JavaScript, date objects are created with new Date()
.
new Date()
returns a date object with the current date and time.
Get the Current Time
const date = new Date();
Date Get Methods
Method | Description |
---|---|
getFullYear() | Get year as a four digit number (yyyy) |
getMonth() | Get month as a number (0-11) |
getDate() | Get day as a number (1-31) |
getDay() | Get weekday as a number (0-6) |
getHours() | Get hour (0-23) |
getMinutes() | Get minute (0-59) |
getSeconds() | Get second (0-59) |
getMilliseconds() | Get millisecond (0-999) |
getTime() | Get time (milliseconds since January 1, 1970) |
Note 1
The get methods above return Local time.
Universal time (UTC) is documented at the bottom of this page.