<div class="time">
            <i class="visa_icon prev"></i><span id="dataTime">2018-6-27 </span> <span id="week" data-id=''>星期三</span><i class="visa_icon next"></i>
        </div>

  

 $(".next").on('click',function(){
//    	next=true;
//    	pre =false;
//    	UpData(pre,next);
//    	 date.yyyy = Number($('.year').text());
//      date.mot = Number($('.month').text());
//      date.dd  =Number($('.data').text());
//    	var newDate = addDate(date,1).split("-");
//    	if(newDate[1]<10){
//    		newDate[1] = 0+newDate[1];
//    	}
//    	if(newDate[2]<10){
//    		newDate[2] = 0+newDate[2];
//    	}
//    	$('.year').text(newDate[0])
//      $('.month').text(newDate[1])
//      $('.data').text(newDate[2])
        reckonTime(1)
      })
      $(".prev").on('click',function(){
//    	next=false;
//    	pre =true;
//    	UpData(pre,next);
//    	 date.yyyy = Number($('.year').text());
//      date.mot = Number($('.month').text());
//      date.dd  =Number($('.data').text());
//    	var newDate = addDate(date,-1).split("-");
//    	if(newDate[1]<10){
//    		newDate[1] = 0+newDate[1];
//    	}
//    	if(newDate[2]<10){
//    		newDate[2] = 0+newDate[2];
//    	}
//    	$('.year').text(newDate[0])
//      $('.month').text(newDate[1])
//      $('.data').text(newDate[2])
 		reckonTime(-1)
      })
})
//日历
function reckonTime(num){
    var dataTime = $("#dataTime");
    var nowDataTime = dataTime.text();
    var arys1 = new Array();
    arys1 = addDate(nowDataTime,num).split('-');//显示的日期
    var ssdate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2]);
    var  week1=String(ssdate.getDay()).replace("0","日").replace("1","一").replace("2","二").replace("3","三").replace("4","四").replace("5","五").replace("6","六");
    var myDate = new Date();
    var nowTime =myDate.toLocaleDateString();//获取今天日期
    var current_time = nowTime;
    var stop_time = addDate(nowDataTime,num);//
    console.log(addDate(nowDataTime,num))
    !CompareDate(current_time,stop_time) 
    && (dataTime.text(addDate(nowDataTime,num)),$("#week").text("星期"+week1));
}
function addDate(date,days){ 
    var d=new Date(date); 
    d.setDate(d.getDate()+days); 
    var m=d.getMonth()+1; 
    m = (m<10)?'0'+m:m;
    var da = d.getDate();
    da = (da<10)?'0'+da:da;
    return d.getFullYear()+'-'+m+'-'+da; 
} 
function CompareDate(d1,d2)
{
  return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}

  

 

posted on 2018-09-19 13:52  刘世涛6192  阅读(907)  评论(0编辑  收藏  举报