Skip to content

Instantly share code, notes, and snippets.

@herusdianto
Created March 24, 2015 07:02
Show Gist options
  • Save herusdianto/71334af5da25a0823df9 to your computer and use it in GitHub Desktop.
Save herusdianto/71334af5da25a0823df9 to your computer and use it in GitHub Desktop.
Javascript Date Interval
<!DOCTYPE html>
<html>
<head>
<title>Javascript Date Interval</title>
<!--
* from benjour answer http://goo.gl/gZWQka
* http://goo.gl/89pfQw
-->
</head>
<body>
<p id="interval"></p>
<script>
showInterval();
function showInterval()
{
var now = new Date;
var lastDay = new Date(now.getFullYear(), 11, 31);
var diff = (lastDay - now) / 1000;
var diff = Math.abs(Math.floor(diff));
var days = Math.floor(diff / (24 * 60 * 60));
var leftSecond = diff - days * 24 * 60 * 60;
var hrs = Math.floor(leftSecond / (60 * 60));
var leftSecond = leftSecond - hrs * 60 * 60;
var min = Math.floor(leftSecond / (60));
var leftSecond = leftSecond - min * 60;
document.getElementById("interval").innerHTML = days + " days " + hrs + " hours " + min + " minutes and " + leftSecond + " seconds.";
setTimeout(showInterval, 1000);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment