批改状态:未批改
老师批语:
倒数计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
div{
font-size: 36px;
width: 1300px;
height: 180px;
margin: 100px auto;
background: #82d743;
line-height: 180px;
text-align: center;
color: #fff;
}
</style>
</head>
<body>
<div>
<p>2019年清明节倒计时 : <span> </span></p>
</div>
<script>
$(function () {
function Time(){
//1秒=1000毫秒;1分钟=60秒;1小时等于3600秒;1天等于86400秒
//先换成秒好用
//d相当于打开文档距离4月5号的时间,以毫秒显示;不知道老师会看到吗?
var d=Date.parse("Apr 05,2019");
//获取当前时间
var s=new Date();
//dd相当于打开文档距离4月5号的时间,以毫秒显示;实时的
var dd=s.getTime();
//获得秒
var rd=Math.floor((d-dd)/1000);
// console.log(rd);
//天 小时 分钟 秒
var day=Math.floor(rd/86400);
var hours=Math.floor(rd%86400/3600);
var minus=Math.floor(rd%3600/60);
var secos=Math.floor(rd%60);//拿到秒钟
// console.log(secos);
$('span').text(day+"天"+hours+"时"+minus+"分"+secos+"秒");
}
// Time()
//setInterval
setInterval(Time,1000);
})
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
总结
1;先获取当前时间到目标时间的 毫秒
2:1秒=1000毫秒;1分钟=60秒;1小时等于3600秒;1天等于86400秒;
3:根据上面的去获取各个变量
4:再去插入文档
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号