日期自动变换(按照某种规律自动变更)

来源:互联网 发布:最流行的编程语言 编辑:程序博客网 时间:2024/04/28 19:04
<!DOCTYPE html>    
<html>    
<head>    
<meta charset="utf-8" />    
<title>测试日期自动变换</title>    
<script>


window.onload=function()
{


var mayDate=new Date();//获取日期
var curMonth=mayDate.getMonth();//获取月份(0-11,0代表1月)
var curDate=mayDate.getDate()//获取日期
var mytime=mayDate.toLocaleTimeString()// //获取当前时间
var week=mayDate.getDay()
weekDay=["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
curMonth+=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){
//月份为:1,3,5,7,8,10,12 时,为大月.则天数为31;
days= 31;
}
else{
//其他月份,天数为:30.
days= 30;

}






//+-------修改时间规律
if(weekDay[week]==="星期一")
{
curDate+=2
}
else if(weekDay[week]==="星期二")
{
curDate+=1;
}
else if(weekDay[week]==="星期三")
{
curDate+=2;
//curDate = days;
}
else if(weekDay[week]==="星期四")
{
curDate+=1;
}
else if(weekDay[week]==="星期五")
{
curDate+=2;
}
else if(weekDay[week]==="星期六")
{
curDate+=1;
}
else
{
curDate;
};

//------当日期超过30天或者31天减回去
// if(curDate>=32)
// {
// curDate-=1;
//
// }
// else if(curDate>=33)
// {
// curDate-=2;
// };
//


//当月是30天
if(days==30)
{
if(days-curDate<0){//超过当月天数
curDate-=days;
curMonth+=1;//把月份调到下个月份
}else{
curDate;
curMonth;
}

}
else if(days==31)//当月31天
{


if(days-curDate<0){//超过当月天数
curDate-=days;
curMonth+=1;//把月份调到下个月份
}else{
curDate;
curMonth;
}
};





//JQ获取所有对象
$(function()
{
$(".curMonth").html(curMonth);
$(".curDate").html(curDate);
});
}


</script>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<style> 
   
.div-relative{position:relative;width:1350px;margin:auto;}  


/*----------修改日期样式01--------------*/  
.div-Month-1{position: absolute;left: 734px;top:197px;width:143px;height:147px;text-align:center;font-family: "微软雅黑", "宋体";font-size: 88px;color: #49b5a8;} /* 月份位置,字体设置 */       
.div-Date-1{ position:absolute;left:954px;top:197px;width:143px; height:147px;text-align:center;font-family: "微软雅黑", "宋体";font-size: 88px;color: #49b5a8;} /* 天数位置,字体设置 */       
/*----------修改日期样式02--------------*/
.div-Month-2{position: absolute;left:334px;top:190px;width: 143px;height: 147px;text-align: center;font-family: "微软雅黑", "宋体";font-size: 88px;color: #D11120;} /* 月份位置,字体设置 */       
.div-Date-2{ position:absolute; left:510px;top:190px; width:143px; height:147px;text-align: center;font-family: "微软雅黑", "宋体";font-size: 88px;color: #D11120;} /* 天数位置,字体设置 */       
  
</style>    
</head>    
<body>    
<div class="div-relative">    
        <img src="images/pic617_cq11ccccccc_01.jpg" >
        <img src="images/pic617_cq11ccccccc_02.jpg" >
        <img src="images/pic617_cq11ccccccc_03.jpg" >
        <img src="images/pic617_cq11ccccccc_04.jpg">
        <img src="images/pic617_cq11ccccccc_05.jpg"> 
        <div class="div-Month-1 curMonth">月份</div>    
        <div class="div-Date-1 curDate">天数</div>      
</div> 


<div style="background:#fffee9;">
    <div style="width:1000px; height:460px; position:relative; margin:auto;">
        <img src="images/s1219_1bjccc.jpg" />  
        <div class="div-Month-2 curMonth">月份</div>    
        <div class="div-Date-2 curDate">天数</div>   
  </div>
</div>   
</body>    
</html>  
0 0
原创粉丝点击