js-倒计时

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SURLIYA/article/details/79977397
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>倒计时</title>
		<script type="text/javascript">
			
			var timeId = window.setInterval("timeDown()", 1000);

			// 1.在网页上显示:"距离2018-05-01剩余xx天xx小时xx分钟x秒"
			// 2.间隔1秒,秒数发生变化
			function timeDown() {
				var date = new Date(2018, 4, 1, 0, 0, 0);
				var times = date.getTime();

				// 当前系统时间
				var sysDate = new Date();
				// 当前系统毫秒数
				var sysTimes = sysDate.getTime();
				// 毫秒差
				var t = times - sysTimes;
				 
				var d = Number.parseInt(t / 1000 / 60 / 60 / 24);
				var h = Number.parseInt(t / 1000 / 60 / 60 % 24);
				var m = Number.parseInt(t / 1000 /60 % 60);
				var s = Number.parseInt(t / 1000 % 60);

				document.getElementById("timeDown").innerHTML = "距离2018-05-01剩余" + d + "天" + h + "小时" + m + "分钟" + s + "秒<br />";
				if(s <= 0) {
					window.clearInterval(timeId);
				}
			}
		</script>
	</head>

	<body>
		<div id = "timeDown"></div>
	</body>
</html>

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页