Javascript Reference - JavaScript Date valueOf() Method








The valueOf() method returns the milliseconds representation of the date as the number of millisecond since midnight January 1, 1970 UTC.

Browser Support

valueOf() Yes Yes Yes Yes Yes

Syntax

dateObject.valueOf();

Parameters

None.





Return Value

A number representing the number of milliseconds between the date object and midnight January 1, 1970 UTC

Example


var date1 = new Date(2007, 0, 1); //"January 1, 2007" 
var date2 = new Date(2007, 1, 1); //"February 1, 2007" 
        
console.log(date1.valueOf());
console.log(date2.valueOf());

The code above generates the following result.

Example 2

< and > calls valueOf method during the comparison.


var date1 = new Date(2007, 0, 1); //"January 1, 2007" 
var date2 = new Date(2007, 1, 1); //"February 1, 2007" 
        
console.log(date1 < date2); //true 
console.log(date1 > date2); //false 

The code above generates the following result.





Example 3

+ sign converts Date value to millisecond.


var stop = + new Date();
console.log(stop);

The code above generates the following result.