马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<title>日期查询</title>
<style>
div.wpdate{
display:inline;
float:left;
margin-left: 60px;
}
div#w_date{
border:2px solid red;
width:200px;
margin-left: 100px;
}
div#w_check{
border:2px solid green;
width:200px;
}
div#w_init{
width:300px;
}
</style>
</head>
<body>
<div style='color:blue;font-size:20px' id="w_init" >
<label>初始日期:</label>
<label id="w_year">2020</label><label>年</label>
<label id="w_month">4</label><label>月</label>
<label id="w_day">16</label><label>日</label>
</div>
<div class="wpdate" id="w_date">
<ul id="w_date ul">
</ul>
</div>
<div class="wpdate" id="w_check">
<ul id="w_check ul">
</ul>
</div>
<script>
//获取公历年某整月的天数//beginDate 需要参加计算的日期,days要添加的天数,返回新的日期,日期格式:YYYY-MM-DD
function getDay(beginDate, days) {
var beginDate = beginDate.split("-");
var nDate = new Date(beginDate[1] + '-' + beginDate[2] + '-' + beginDate[0]); //转换为MM-DD-YYYY格式
var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
var rDate = new Date(millSeconds);
var year = rDate.getFullYear();
var month = rDate.getMonth() + 1;
if (month < 10) month = "0" + month;
var date = rDate.getDate();
if (date < 10) date = "0" + date;
return (year + "-" + month + "-" + date);
}
let beg_year=$("#w_year").text();
let beg_month=$("#w_month").text();
let beg_day=$("#w_day").text();
let beg_date=beg_year+"-"+beg_month+"-"+beg_day;
for(var i=0;i<24;i++){
let str="";
if (i%3==2){
str="<li style='color:blue;font-size:20px'>"+getDay(beg_date,28)+"</li>";
}
else{
str="<li style='color:blue;font-size:20px'>"+getDay(beg_date,28)+"</li>";
}
$("#w_date ul").append(str);
beg_date=getDay(beg_date,28);
}
let beg_date2=beg_year+"-"+beg_month+"-"+beg_day;
for(var i=0;i<8;i++){
let str="";
str="<li style='color:red;font-size:20px'>"+getDay(beg_date2,90)+"</li>";
$("#w_check ul").append(str);
beg_date2=getDay(beg_date2,90);
}
</script>
</body>
</html>
|