今天看到一個帖子求項(xiàng)目完成的時間,需求是這樣的:
給你一個項(xiàng)目的開始時間,給你項(xiàng)目總需求的天數(shù),求項(xiàng)目的項(xiàng)目結(jié)束時間?注意:周六周日為休息日。
在asp編程開發(fā)中,計(jì)算時間很容易,直接用項(xiàng)目開始時間+天數(shù),即可得到項(xiàng)目結(jié)束時間,但這里麻煩就在要排除周六和周日這兩個休息時間。
經(jīng)過思考,代碼寫出來了,放在這里和大家分享一下:
<% starttime=cdate("2013-09-08") '項(xiàng)目開始時間 endtime="" '項(xiàng)目結(jié)束時間 num=8 '項(xiàng)目需要的天數(shù) response.write "開始時間:"&starttime&"<br>天數(shù):"&num&"<br>結(jié)束時間:" starttime=starttime-1 i=1 while i <= num starttime=starttime+1 w=weekday(starttime) if w>1 and w<7 then '非周末 endtime=starttime i=i+1 else '周末休息 end if wend response.write endtime %>
(鼠標(biāo)移到代碼上去,在代碼的頂部會出現(xiàn)四個圖標(biāo),第一個是查看源代碼,第二個是復(fù)制代碼,第三個是打印代碼,第四個是幫助)
運(yùn)行一下,即可看到結(jié)果。你也可以修改一下里面的項(xiàng)目開始時間和項(xiàng)目天數(shù),再通過萬年歷來比較檢查一下它的計(jì)算結(jié)果是否正確。