salesforce中 计算working day

public with sharing class NETWORKDAY {

public void NETWORKDAY(){

//datetime s = datetime.today();
Datetime s = Datetime.newInstance(2014, 10, 22);
Datetime e = Datetime.newInstance(2014, 10, 13);
NETWORKDAY d = new NETWORKDAY();
d.diff(s,e);
}

public integer diff(Datetime sdate, Datetime edate){
integer count=0;
Date d1 = Date.valueOf(sdate);
Date d2 = Date.valueOf(edate);
integer wDay = d1.daysBetween(d2) ;

do{
if(sdate.format('EEEE') == 'Saturday') {
count++;
}
if(sdate.format('EEEE') == 'Sunday') {
count++;
}
sdate= sdate.adddays(1);
}while(sdate<=edate);

wDay = wDay-count+1;
system.debug('*************'+wDay);
return wDay;
}

}

猜你喜欢

转载自www.cnblogs.com/linnan/p/9130139.html