html时间倒计时

文章目录

  • 一、HTML+js[时间倒计时]
    • 输出结果


一、HTML+js[时间倒计时]


<html>
	<head>
		<meta charset="utf-8">
		<title> 时间倒计时title>
	head>
	<body>
		
		<div id="date" style="margin:0 auto;">div>
	body>
	<script type="text/javascript">
		function Date_count_down(jztime, divname) {
			var now = new Date();
			var endDate = new Date(Date.parse(jztime.replace(/-/g, "/")));
			var leftTime = endDate.getTime() - now.getTime();
			var leftsecond = parseInt(leftTime / 1000);
			var day = Math.floor(leftsecond / (60 * 60 * 24));//天数
			var hour = Math.floor((leftsecond - day * 24 * 60 * 60) / 3600);//小时
			var minute = Math.floor((leftsecond - day * 24 * 60 * 60 - hour * 3600) / 60);//秒
			var date_d = document.getElementById(divname);
			date_d.innerHTML = "距离2021-6-30还剩余" + day + "天" + hour + "时" + minute +"分";
		}
		var engTime = "2021-6-30"; //截止时间
		window.setInterval(function() {
			Date_count_down(engTime, 'date');
		}, 1000);
	script>
html>

输出结果

html时间倒计时_第1张图片

你可能感兴趣的:(javascript,html)