代码如下
<!DOCTYPE html>
<html>
<head>
<style>
body{
width: 100%;
height: 600px;
}
div{
width:40%;
height:30%;
background-color: grey;
display: flex;
justify-content: center;
color:white;
margin:0 auto;
font-size: 32px;
align-items: center;
}
</style>
<title>距离下次发工资还有</title>
<script type="text/javascript">
var nowObj = new Date();
console.log(nowObj)
if (nowObj.getDate()>=5) {
var nextMonth = nowObj.getMonth()+1;
}else{
nextMonth = nowObj.getMonth();
}
//5是发工资的时间
//nextDate是下次发工资的时间
var nextDate = new Date(nowObj.getFullYear(),nextMonth,5);
var now = new Date();
var payTime = parseInt(nextDate - now);
payTime = Math.ceil(payTime/1000/(60*60*24));
// if(weekwhat==6||weekwhat==0){
// if(weekwhat==6)payTime=+2;
// if (weekwhat==0)payTime=+1;
// }
payTime = payTime+'天';
console.log(nextDate.getDay());
// console.log(nextMonth);
// console.log(now);
// console.log(nextDate-now);
document.write("<div>"+payTime+"</div>");
</script>
</head>
<body>
</body>
</html>
效果如下