Skip to main content
Back to Blog
Web DevelopmentProgramming Languages
5 April 20264 min readUpdated 5 April 2026

Understanding JavaScript Date Retrieval Methods

JavaScript Date Retrieval Methods Creating Date Objects with In JavaScript, you can create date objects using the constructor. This function returns a date object that holds the...

Understanding JavaScript Date Retrieval Methods

JavaScript Date Retrieval Methods

Creating Date Objects with new Date()

In JavaScript, you can create date objects using the new Date() constructor. This function returns a date object that holds the current date and time.

Methods for Retrieving Date Information

JavaScript provides several methods to extract specific components from a date object. The following methods return information in local time:

  • getFullYear(): Returns the year as a four-digit number (e.g., 2023).
  • getMonth(): Returns the month as a number, where January is 0 and December is 11.
  • getDate(): Returns the day of the month as a number (1-31).
  • getDay(): Returns the day of the week as a number (0-6), with Sunday as 0.
  • getHours(): Returns the hour (0-23).
  • getMinutes(): Returns the minutes (0-59).
  • getSeconds(): Returns the seconds (0-59).
  • getMilliseconds(): Returns the milliseconds (0-999).
  • getTime(): Returns the number of milliseconds since January 1, 1970.

Illustration for: - getFullYear(): Returns the...

It's important to note that these methods provide information from the static point in time represented by the date object. This means the object's time is not continuously updating.

Detailed Method Descriptions

The getFullYear() Method

Use getFullYear() to obtain the full year from a date object. Avoid using the deprecated getYear() method, which was intended to return a two-digit year.

The getMonth() Method

The getMonth() method provides the month as a number from 0 to 11. To convert this to a month name, consider using an array of month names.

The getDate() Method

Retrieve the day of the month with getDate(), which returns a value from 1 to 31.

The getHours() Method

To get the hour from a date object, use getHours(), which outputs a number between 0 and 23.

The getMinutes() Method

getMinutes() extracts the minutes from a date, ranging from 0 to 59.

The getSeconds() Method

For the seconds component, apply getSeconds(), which yields a value between 0 and 59.

The getMilliseconds() Method

getMilliseconds() returns the milliseconds of a date, a number between 0 and 999.

The getDay() Method

Use getDay() to determine the day of the week, noted as a number from 0 (Sunday) to 6 (Saturday).

The getTime() Method

getTime() provides the total milliseconds elapsed since the epoch time, January 1, 1970.

The Date.now() Method

The Date.now() method is a static method that returns the current time in milliseconds since the epoch. It is used directly on the Date object, not on instances.

UTC Date Retrieval Methods

JavaScript also offers methods to get date and time components based on Coordinated Universal Time (UTC):

  • getUTCDate(): Equivalent to getDate(), but for UTC.
  • getUTCFullYear(): Equivalent to getFullYear() for UTC.
  • getUTCMonth(): Equivalent to getMonth() for UTC.
  • getUTCDay(): Equivalent to getDay() for UTC.
  • getUTCHours(): Equivalent to getHours() for UTC.
  • getUTCMinutes(): Equivalent to getMinutes() for UTC.
  • getUTCSeconds(): Equivalent to getSeconds() for UTC.
  • getUTCMilliseconds(): Equivalent to getMilliseconds() for UTC.

These methods use UTC time, which is equivalent to Greenwich Mean Time (GMT).

Understanding Timezone Differences

The getTimezoneOffset() method calculates the difference, in minutes, between local time and UTC time. This can vary significantly depending on geographical location.