根据开始和结束日期打印HTML日历片段

 //日历打印


 function  getWeek(date) {  //获取星期
     return new Array("", "", "", "", "", "", "")[new Date(date).getDay()];
 }

 function addDays(date,count) { //添加日期
     var dd = new Date(date);
     dd.setDate(dd.getDate() + count);
     var y = dd.getFullYear(), m = dd.getMonth() + 1, d = dd.getDate();
     return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
 }

 function disDays(date1, date2){  //根据两个容器日期的值相减的得到天数
     date1 = date1.split("-");
     date2 = date2.split("-");
     var start = new Date(date1[0], date1[1] - 1, date1[2]);
     var end = new Date(date2[0], date2[1] - 1, date2[2]);
     return parseInt((end - start) / 1000 / 60 / 60 / 24);
 }


function printDate(){ //创建Html片段
    var startDate = $("#txt_create_start_date").val();
    var endDate = $("#txt_create_end_date").val();
    var disCount = disDays(startDate,endDate);
    var html = "";
    html += "";
    html += "";
    for (var i=0,len=disCount; i<len+1; i++){
        var curr = addDays(startDate,i);
        var short = curr.substr(5,curr.length).replace("-",".");
        html += "";
    }
    html += "
正常
工时累计
加班
工时累计
"; html += ""+short+" "+getWeek(curr)+""; html += " 正常   加班"; html += "
"
; $("#table-right-head").html(html); }

你可能感兴趣的:(根据开始和结束日期打印HTML日历片段)