Created
March 24, 2015 07:02
-
-
Save herusdianto/71334af5da25a0823df9 to your computer and use it in GitHub Desktop.
Javascript Date Interval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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