js 现在的时间距离本月月底的倒计时(html)
发布时间:2023年12月22日
现在的时间距离本月月底的倒计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>现在的时间距离本月月底的倒计时</title>
<style>
body {
padding: 0;
margin: 0;
}
.index-time {
color: #333333;
text-align: left;
font-size: 28px;
line-height: 80px;
width: 550px;
margin: 0 auto;
}
.index-date {
color: #ff5722;
}
</style>
</head>
<body>
<div class="index-time">
<div class="index-date" id="date"></div>
<div class="index-date" id="reachDate"></div>
<div class="index-time-son">
<div class="time-son-m" id="timer">
距离指定日期:
<span class="time-hei time-hei1">00</span> 天
<span class="time-hei time-hei2">00</span> 小时
<span class="time-hei time-hei3">00</span> 分
<span class="time-hei time-hei4">00</span> 秒
</div>
</div>
</div>
<script>
function getDays() {
var date = new Date();
var year = date.getFullYear();
var mouth = date.getMonth() + 1;
var days = date.getDate();
var myDate = date.getDate();
var hours = date.getHours();
var min = date.getMinutes();
var second = date.getSeconds();
var Milliseconds = date.getMilliseconds();
document.getElementById('date').innerHTML = '当前时间:' + year + '-' + mouth + '-' + days + ' ' + hours + ':' + min + ':' + second;
if (mouth == 2) {
days = year % 4 == 0 ? 29 : 28;
} else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) {
days = 31;
} else {
days = 30;
}
document.getElementById('reachDate').innerHTML = '指定时间:' + year + '-' + mouth + '-' + days;
var differenceday = days - myDate - 1;
differenceday = differenceday > 9 ? differenceday : "0" + differenceday;
var differencehours = 1 * 23 - hours;
differencehours = differencehours > 9 ? differencehours : "0" + differencehours;
var differencemin = 1 * 59 - min;
differencemin = differencemin > 9 ? differencemin : "0" + differencemin;
var differencesecond = 1 * 59 - second;
differencesecond = differencesecond > 9 ? differencesecond : "0" + differencesecond;
var timer = document.getElementById('timer');
var span = timer.getElementsByTagName('span');
span[0].innerHTML = differenceday;
span[1].innerHTML = differencehours;
span[2].innerHTML = differencemin;
span[3].innerHTML = differencesecond;
};
var timer = window.setInterval(function () {
getDays();
}, 1000);
</script>
</body>
</html>
文章来源:https://blog.csdn.net/DHLSP15/article/details/135151682
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!