VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-date-valueof-method/

⇱ JavaScript Date valueOf() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Date valueOf() Method

Last Updated : 11 Jul, 2025

The date.valueOf() method is used to get the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date. 

Syntax:

dateObj.valueOf()

Parameters:

This method does not accept any parameter. It is just used along with a Date object created using Date() constructor. 

Return Values:

It returns the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date as the contents of the Date() constructor. 

Note: The DateObj is a valid Date object created using Date() constructor whose contents are used to get the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date as the contents of the Date() constructor. 

Example 1: This example shows the use of JavaScript Date valueOf() Method.

Output:

845337932000

Example 2: If nothing as a parameter is passed while creating a date object but still the valueOf() method returns the number of milliseconds between 1 January 1970 00:00:00 UTC and the current date. 

Output:

1524387231290

Example 3: Date of a month ranging between 1 to 31. If the date is taken as 35 which is out of the date range, it returns NaN i.e, not a number. 

Output:

NaN

Some Important Points:

  • Months, Dates, hours, minutes, seconds, and milliseconds should all be in their respective range. Otherwise valueOf() method returns NaN i.e, not a number.
  • The range of Months, Dates, hours, minutes, seconds, and milliseconds are 0 to 11, 1 to 31, 0 to 23, 0 to 59, 0 to 59, and 0 to 999 respectively.

We have a complete list of Javascript Date Objects, to check those please go through this article.

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Opera
  • Safari
Comment