Calculate date difference using getTime( ) - Javascript Date

Javascript examples for Date:getTime

Description

Calculate date difference using getTime( )

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w w w .  ja  v a 2s  . c o m*/
var datePhp = new Date(2018, 5, 4, 9, 30, 0),
    today = new Date(2018, 5, 2, 9, 30, 0);
if (datePhp > today) {
    var difference = (datePhp.getTime() - today.getTime()) / (1000*60*60);
    document.getElementById('res').innerHTML = difference;
}
    }

      </script> 
   </head> 
   <body> 
      <div id="res"></div>  
   </body>
</html>

Related Tutorials