首页 > 代码库 > 计算工时

计算工时

var realMonth = parseInt(prompt("请输入月份:",""));

console.log(realMonth);

var arr = document.getElementsByClassName("l-grid-body-table");

var arr1 = arr[1].children;

var arr2 = arr1[0].children;

var arr3 = arr2[0];

var arr4 = arr3.children;

var node;

var div;


var month;

var day;

var preMin;

var preH;

var sufMin;

var sufH;

var totaltime = 0;


for(var i=0;i < arr2.length;i++){

//取出月份

node = arr2[i].children;

div = node[4].children;

month = div[0].innerHTML.substring(5,7);

day = div[0].innerHTML.substring(8,10);

if(month == realMonth){

if(day==11||day==27||day==28)continue;

//取出上班打卡

div = node[5].children;

preH = parseInt(div[0].innerHTML.substring(0,2));

preMin =parseInt(div[0].innerHTML.substring(3,5));

//取出下班打卡

div = node[6].children;

sufH = parseInt(div[0].innerHTML.substring(0,2));

sufMin = parseInt(div[0].innerHTML.substring(3,5));

//计算今天的多出的工作时间

preH >=8 ? totaltime += ((preH-8)*60 + preMin)*-1:totaltime+=0;

sufH >=18 ? totaltime += (sufH-18)*60 + sufMin:totaltime+=0;

console.log("day:" + day);

}else if(month < realMonth){

console.log("break!");

break;

}

}

console.log("The total time is :" + totaltime);


计算工时