Created
April 8, 2013 08:04
-
-
Save mfine2/5335059 to your computer and use it in GitHub Desktop.
show left time
This file contains 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<div id="left"></div> | |
<script type="text/javascript"> | |
var showLeftTime = function (endStr, node) { | |
var endTime = new Date(endStr), | |
nowTime = (new Date()).getTime(), | |
timeSpan = endTime - nowTime, | |
seconds = timeSpan / 1000, | |
minutes = seconds / 60, | |
hours = minutes / 60, | |
days = hours / 24, | |
leftDays = Math.floor(days), | |
leftHours = Math.floor(hours % 24), | |
leftMinutes = Math.floor(minutes % 60), | |
leftSeconds = Math.floor(seconds % 60); | |
node.innerHTML = leftDays + '天' + leftHours + '小时' + leftMinutes + '分钟' + leftSeconds + '秒'; | |
setTimeout(function() { | |
showLeftTime(endStr, node); | |
}, 1000); | |
}; | |
var now = new Date(), | |
endStr = now.setDate(now.getDate() + 1), | |
node = document.getElementById('left'); | |
showLeftTime(endStr, node); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment