Javascript Data Type How to - Create time countdown








Question

We would like to know how to create time countdown.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from  w  w w . j ava  2 s.  c  o m-->
function Bouwen(BouwKlaar) {
    var bouwtijd = BouwKlaar;
    var dag = (new Date(bouwtijd - (new Date()))).getUTCDay();
    var uur = (new Date(bouwtijd - (new Date()))).getUTCHours();
    var min = (new Date(bouwtijd - (new Date()))).getUTCMinutes();
    var sec = (new Date(bouwtijd - (new Date()))).getUTCSeconds();
    return dag + ":" + uur + ":" + min + ":" + sec;
}
setInterval(function () {
    var bouw = Bouwen(new Date(2013, 05, 21, 20, 00, 00));
    document.writeln(bouw);
}, 1000);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: