失忆的硬盘

C#实现工作日加减(去周末)
public DateTime addWorkDays(DateTime dt,int addDays)
        {
            DateTime dtStart 
= dt;
            DateTime dtEnd 
= dtStart.AddDays(-addDays);
            
int days = CalculateWeekendDays(dtStart,dtEnd);
            
while(days>0)
            {
                dtStart 
= dtEnd;
                dtEnd 
= dtEnd.AddDays(-days);
                days 
= CalculateWeekendDays(dtStart,dtEnd);
            }
            
return dtEnd;
        }

        
public  int CalculateWeekendDays(DateTime  dtStart,  DateTime dtEnd)
        {
            
int  count=0;
            
for(DateTime  dtTemp = dtStart;dtTemp > dtEnd;dtTemp = dtTemp.AddDays(-1))
            {
                
if(dtTemp.DayOfWeek==DayOfWeek.Saturday||dtTemp.DayOfWeek==DayOfWeek.Sunday)
                {
                    count
++;
                }
            }
            
return  count;
        }

posted on 2008-08-08 16:13  失忆的硬盘  阅读(731)  评论(0编辑  收藏  举报