How and when to use date value in milliseconds
Description
The valueOf()
method returns
the milliseconds representation of the date.
Example
var date1 = new Date(2007, 0, 1); //"January 1, 2007"
var date2 = new Date(2007, 1, 1); //"February 1, 2007"
/*from w w w . j av a 2 s. c o m*/
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"
/*from www. j a v a2s. co m*/
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.