Date valueOf()

The valueOf() method returns the milliseconds representation of the date.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var date1 = new Date(2007, 0, 1); //"January 1, 2007" 
        var date2 = new Date(2007, 1, 1); //"February 1, 2007" 
        
        document.writeln(date1.valueOf());
        document.writeln(date2.valueOf());
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var date1 = new Date(2007, 0, 1); //"January 1, 2007" 
        var date2 = new Date(2007, 1, 1); //"February 1, 2007" 
        
        document.writeln(date1 < date2); //true 
        document.writeln(date1 > date2); //false 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

< and > calls valueOf method during the comparison.

Home 
  JavaScript Book 
    Essential Types  

Date:
  1. Date Type
  2. Date getter
  3. Date Setter
  4. Date.parse()
  5. Date.UTC()
  6. Date.now()
  7. Date toLocaleString()
  8. Date toString()
  9. Date valueOf()
  10. Date toDateString()
  11. Date toTimeString()
  12. Date toLocaleDateString()
  13. Date toLocaleTimeString()
  14. Date toUTCString()