DateTime otime; 
DateTime ctime; 
ctime = DateTime.Parse("2009-4-5 08:00:00"); 
otime = DateTime.Parse("2009-4-6 12:31:22); 
工作时间 9:00-5:00 为有效时间 
计算出otime 和 ctime 之间 的工作时间有多少分钟 
上面的例子 工作时间就是 5号 8个小时 6号 3个小时31分钟 
所以结果就是 480+211= 691 分 我想问下代码该如何写 麻烦大家了

解决方案 »

  1.   

    (otime-ctime).Minutes这种问题就算不去看MSDN,看看VS的智能提示也出来了...现在的新人怎么都这么懒...
      

  2.   

    。主要是因为 有效时间段的 问题  otime   和 ctime 都是动态的数据 不知道 该怎么做 谁给个思路啊
      

  3.   


                int Minutes = 0;//总分钟数            DateTime otime;
                DateTime ctime;
                ctime = DateTime.Parse("2009-4-5 08:00:00");
                otime = DateTime.Parse("2009-4-6 18:11:00");            TimeSpan timeC;//有效的起始时间
                TimeSpan timeO;//有效的未端时间            timeC = TimeSpan.Parse("9:00");
                timeO = TimeSpan.Parse("17:00");            //完全工作一天所用的时间
                double minFull = ((TimeSpan)(timeO - timeC)).TotalMinutes;            //从上班时间到15点的工时
                double minCFull = (timeO > ctime.TimeOfDay && timeC < ctime.TimeOfDay) ? ((TimeSpan)(timeO - ctime.TimeOfDay)).TotalMinutes : minFull;
                //从9点起到下班时间的工时
                double minOFull = (timeO > otime.TimeOfDay && timeC < otime.TimeOfDay) ? ((TimeSpan)(otime.TimeOfDay - timeC)).TotalMinutes : minFull;
                //计算工作天数
                int days = (int)((TimeSpan)(otime - ctime)).TotalDays;            //按一天算的工作时间
                Minutes = (int)(minCFull + minOFull + (int)(days-1) * minFull) ;