当前位置 : 主页 > 网络编程 > JavaScript >

每月简单值日周期程序

来源:互联网 收集:自由互联 发布时间:2021-07-03
简单值日周期程序,js简单值日安排程序,不含节假日 1. [代码] [JavaScript]代码 style type="text/css"table.altrowstable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border
简单值日周期程序,js简单值日安排程序,不含节假日

1. [代码][JavaScript]代码    

<style type="text/css">
table.altrowstable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #a9c6c9;
    border-collapse: collapse;
}
table.altrowstable th {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
table.altrowstable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
.oddrowcolor{
    background-color:#d4e3e5;
}
.evenrowcolor{
    background-color:#c3dde0;
}
</style>
<script>
DateDiffNoWeekDay(new Date("2016/08/01 14:30:00"),new Date("2016/08/31 12:30:00"));
function carryTime(date){
	if(date.getMinutes()>0&&date.getMinutes()<15){
		date.setMinutes(0);
	}
	if(date.getMinutes()>=15&&date.getMinutes()<30){
		date.setMinutes(30);
	}
	if(date.getMinutes()>30&&date.getMinutes()<45){
		date.setMinutes(30);
	}
	if(date.getMinutes()>=45){
		date.setHours(date.getHours()+1);
		date.setMinutes(0);
	}
	return date;
}
function DateDiffNoWeekDay(startTime,endTime){
    if(startTime>=endTime) return 0;
    startTime=carryTime(startTime);
    endTime=carryTime(endTime);
    var totalTime=0;
    if(startTime.getDay()==6||startTime.getDay()==0){
    	totalTime=endTime.getDate()-startTime.getDate();
    }else{
    	totalTime=Math.floor(((endTime-startTime)/(3600*1000))/24);
    }
    var tempStartTime=new Date();
    tempStartTime.setTime(startTime.getTime());
    var temp=0;



    while(tempStartTime.getDate()<endTime.getDate()){
    	if(tempStartTime.getDay()==6||tempStartTime.getDay()==0){
    		totalTime--;
   		}
    	tempStartTime.setDate(tempStartTime.getDate()+1);
   }



   do{
    	if(startTime.getDay()==6 || startTime.getDay()==0){
    	 	startTime.setDate(startTime.getDate()+1);
    	 	startTime.setHours(9);
    	 	startTime.setMinutes(0);
    	 	continue;
    	}
        if(startTime.getHours()*60+startTime.getMinutes()>=9*60 && startTime.getHours()*60+startTime.getMinutes()<17*60){
            temp+=0.05;
        }
        startTime.setTime(startTime.getTime()+0.5*3600*1000);
    }while(startTime.getHours()*60+startTime.getMinutes()!=endTime.getHours()*60+endTime.getMinutes())
    totalTime+=Math.floor(temp/0.8);
    totalTime+=temp%0.8;
    totalTime=Math.round(totalTime*100)/100
    var days=Math.floor(totalTime);
    var hours=Math.round((totalTime-days)*100)/10;
    document.write(" <u>  "+days+"  </u>day<u>   "+hours+"  </u>hour");
    return totalTime;
}

 var swapItems = function(arr, index1, index2) {
        arr[index1] = arr.splice(index2, 1, arr[index1])[0];
        return arr;
    };
function getLastDay(){
    var dt = new Date();
    dt.setDate(1);
    dt.setMonth(dt.getMonth()+1);
    cdt = new Date(dt.getTime()-1000*60*60*24);

    return cdt.getDate()
   
}

function altRows(id){
    if(document.getElementsByTagName){  
        
        var table = document.getElementById(id);  
        var rows = table.getElementsByTagName("tr"); 
         
        for(i = 0; i < rows.length; i++){          
            if(i % 2 == 0){
                rows[i].className = "evenrowcolor";
            }else{
                rows[i].className = "oddrowcolor";
            }      
        }
    }
}

window.onload=function(){
    altRows('TurnTable');
}
 function getInfo(year, month) {
        var d = new Date();
        // what day is first day
        d.setFullYear(year, month-1, 1);
        var w1 = d.getDay();
        if (w1 == 0) w1 = 7;
        // total day of month
        d.setFullYear(year, month, 0);
        var dd = d.getDate();
        // first Monday
        if (w1 != 1) d1 = 7 - w1 + 2;
        else d1 = 1;
        week_count = Math.ceil((dd-d1+1)/7);
        document.write(year + "年" + month + "月有" + week_count +"周<br/>");


        var TurnPerson = new Array("邵飞1","邵飞11","邵飞2","邵飞3","邵飞4","邵飞5","邵飞6");

        var TurnTemp = new Array("","","","","","")

          document.write('<table id="TurnTable"><tr><th>星期一</th><th>星期二</th><th>星期三</th><th>星期四</th><th>星期五</th></tr>');
        for (var i = 0; i < week_count; i++) {
            var monday = d1+i*7;
            var sunday = monday + 6;
            var from = year+"/"+month+"/"+monday;
            var to;
            if (sunday <= dd) {
                to = year+"/"+month+"/"+sunday;
            } else {
                d.setFullYear(year, month-1, sunday);
                to = d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate();
            }
            //document.write("第"+(i+1)+"周 从" + from + " 到 " + to + "<br/>");

            
             document.write("<tr>");
             var  monthlastbz = 1;
            for(var j=0;j<5;++j){
                     
                    if(TurnPerson.length <= j){
                         document.write("第"+(i+1)+"周 从" +month+ "/"+(monday+j) + " 到 " + TurnPerson[j%TurnPerson.length] + "<br/>");

                    }else{
                           if((monday+j) >getLastDay()){
                                document.write("<td>"+(month+1)+ "/"+(monthlastbz++)+ TurnPerson[j]+"</td>");
                            }
                            else
                                document.write("<td>"+month+ "/"+(monday+j)+ TurnPerson[j]+"</td>");
                       
                       //document.write("第"+(i+1)+"周 从" + (monday+j) + " 到 " + TurnPerson[j] + "<br/>");
                       

                   }


                   if(j == 4){


                            
                        if(TurnPerson.length > 5){
                            
                            var be =0
                            for(var t = 5;t<TurnPerson.length;++t){
                                     var temp= TurnPerson[t]
                                      
                                   TurnTemp[be++] = temp
                                      

                            }

                            for(var BeginArray = 0;BeginArray < 5;++BeginArray){

                                   TurnTemp[be++] = TurnPerson[BeginArray]
                                   console.log("TurnTemp[BeginArray]" +TurnTemp[BeginArray+5])
                            }
                                
                            for(var e = 0;e<TurnTemp.length;++e){

                                 TurnPerson[e] = TurnTemp[e]
                            }

                        }

                       
                   }

            }
             document.write("</tr>");
            
           
        }
        document.write("</table>");
    }

     var date=new Date;

    getInfo(date.getFullYear(),date.getMonth()+1);
</script>
网友评论