JavaScript Get Date Methods


The new Date() Constructor

To make a date in JavaScript, you use new Date().

new Date() provides you with a date object showing the current date and time.


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.

The time called Universal Time (UTC) is written at the bottom of this page.

Note 2

The get methods give you details from date objects you already have.

In a date object, the time doesn't change. The clock is not running.

The time stored in a date object isn't the same as the current time.


The getFullYear() Method

The getFullYear() function gives you the year of a date in a four-digit format.


Warning !

Some older JavaScript code might use a method called getYear() which is not standard.

The function getYear() should give back a year in a short, two-digit format.

getYear() is deprecated. Do not use it!


The getMonth() Method

The getMonth() function gives you the month of a date, but it's represented as a number from 0 to 11.

Note

In JavaScript, January is represented by the number 0, February by 1, and so on.

December, on the other hand, is represented by the number 11.

Note

You can use an array of names to return the month as a name:


The getDate() Method

The getDate() function gives you the day of a date as a number from 1 to 31.


The getHours() Method

The getHours() function gives you the time in hours as a number, ranging from 0 to 23, from a given date.


The getMinutes() Method

The getMinutes() function gives you the number of minutes in a date, ranging from 0 to 59.


The getSeconds() Method

The getSeconds() function gives you the number of seconds in a date, ranging from 0 to 59.


The getMilliseconds() Method

The getMilliseconds() function gives you the number of milliseconds in a date, ranging from 0 to 999.


The getDay() Method

The getDay() function gives you the day of the week as a number (0-6) for a specific date.

Note

In JavaScript, Sunday is considered the first day of the week, marked as day 0.

However, in some countries, Monday is seen as the beginning of the week instead of Sunday.

Note

You can use an array of names, and getDay() to return weekday as a name:


The getTime() Method

The getTime() function gives you the count of milliseconds that have passed since January 1, 1970.


The Date.now() Method

The Date.now() function gives you the count of milliseconds that have passed since January 1, 1970.

The Date.now() function is a feature of the Date object and returns the current timestamp.

You can't apply it to a date object, for example, like this: myDate.now().

The syntax is always Date.now().


UTC Date Get Methods

Method Same As Description
getUTCDate() getDate()Returns the UTC date
getUTCFullYear() getFullYear()Returns the UTC year
getUTCMonth() getMonth()Returns the UTC month
getUTCDay() getDay()Returns the UTC day
getUTCHours() getHours()Returns the UTC hour
getUTCMinutes() getMinutes()Returns the UTC minutes
getUTCSeconds() getSeconds()Returns the UTC seconds
getUTCMilliseconds() getMilliseconds()Returns the UTC milliseconds

The getTimezoneOffset() Method

The getTimezoneOffset() function gives you the time difference, in minutes, between your local time and UTC time.