Skip to content

Date class in JavaScript

Date instantiation and properties

A date consists of a year, a month, a day, an hour, a minute, a second and milliseconds.

Initiating a new Date object with no arguments creates a date instance with the current date and time. You can pass arguments to create a specified date.

new Date(milliseconds)
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)

Dates in JavaScript are created in milliseconds starting from 1 January 1970 at 00:00:00 UTC

1 day = 86,400,000 milliseconds

Months start from January and are counted from 0

Date methods

Method Description
getFullYear() gets the year
getMonth() gets the month
getDate() gets the date of the month
getDay() gets the day of the week
getHours()
getMinutes()
getSeconds()
getMilliseconds()