A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-date-valueof-method/ below:

JavaScript Date valueOf() Method - GeeksforGeeks

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.

javascript
// Here a date has been assigned
// while creating Date object
let dateobj =
    new Date('October 15, 1996 05:35:32');

// Getting the number of milliseconds between 
// 1 January 1970 00:00:00
// UTC and the given date as the content of 
// the above Date() constructor.
let B = dateobj.valueOf();

// Printing the calculated number
// of milliseconds.
console.log(B);

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. 

javascript
// Here nothing has been assigned
// while creating Date object
let dateobj = new Date();

// Getting the number of milliseconds between 
// 1 January 1970 00:00:00
// UTC and the current date.
let B = dateobj.valueOf();

// Printing the calculated number 
// of milliseconds.
console.log(B);

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. 

javascript
// Here a date has been assigned
// while creating Date object
let dateobj = new Date('October 35, 1996 05:35:32');

// Getting the number of milliseconds between 
// 1 January 1970 00:00:00
// UTC and the given date.
let B = dateobj.valueOf();

// Printing the calculated number 
// of milliseconds.
console.log(B);

Output:

NaN

Some Important Points:

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

Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4