现在的时间距离本月月底的倒计时

<!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>
</head>

<body>
<div class="index-time">
<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() {



//1 . 获取本月的天数

var date = new Date();
var year = date.getFullYear();
var mouth = date.getMonth() + 1;
var days;
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;
}
// 2.本月的天数 - 用本月已经过去的时间 (天数 小时 分钟 秒数)
var myDate = new Date().getDate();
var hours = new Date().getHours();
var min = new Date().getMinutes();
var second = new Date().getSeconds();
var Milliseconds = new Date().getMilliseconds();

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://www.cnblogs.com/shenbo666/p/9389155.html