Javascript Data Type How to - Count second down








Question

We would like to know how to count second down.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   ww  w .ja v  a  2s  .  co  m-->
var serverDate = new Date(2013,12,06,0,0,0);
var closeDate = new Date(2013,12,06,0,1,0);
var clientDate = new Date();
var timeDiff = clientDate - serverDate;
$('#timediff').html(timeDiff);
setInterval(function() {
    var remainingMillisecs = closeDate - (new Date()) + timeDiff;
    var remainingSeconds = remainingMillisecs / 1000;
    $('#remaining').html(parseInt(remainingSeconds));
}, 1000);
});
</script>
</head>
<body>
  <div id="timediff"></div>
  <div id="remaining"></div>
</body>
</html>

The code above is rendered as follows: