最简单的方法就是从起始时间到结束时间一天一天的判断,如果是周一至周五则累加

解决方案 »

  1.   

    我这个算法比较粗笨,如果你有兴趣可以改进
    *计算结果不包括起止当天tm * ptmStartDateTime = new tm;
    tm * ptmEndDateTime = new tm;
    time_t ttStartDateTime;
    time_t ttEndDateTime;
    int nWorkDay = 0;// You should set the value of year, month, day of month, hour, minute and second here
    ptmStartDateTime->tm_year = ;
    ptmStartDateTime->tm_mon = ;
    ptmStartDateTime->tm_mday = ;
    ptmStartDateTime->tm_hour = ;
    ptmStartDateTime->tm_min = ;
    ptmStartDateTime->tm_sec = ;ptmEndDateTime->tm_year = ;
    ptmEndDateTime->tm_mon = ;
    ptmEndDateTime->tm_mday = ;
    ptmEndDateTime->tm_hour = ;
    ptmEndDateTime->tm_min = ;
    ptmEndDateTime->tm_sec = ;ttStartDateTime = mktime(ptmStartDateTime);
    ttEndDateTime = mktime(ptmEndDateTime);while (TRUE)
    {
      ttStartDateTime += (24 * 60 * 60);
      if (ttStartDateTime >= ttEndDateTime)
        break;
      if (ptmStartDateTime->tm_year == ptmEndDateTime->tm_year && ptmStartDateTime->tm_yday == ptmEndDateTime->tm_yday)
        break;
      ptmStartDateTime = localtime(&ttStartDateTime);
      if (ptmStartDateTime->tm_wday > 0 && ptmStartDateTime->tm_wday < 6)
      {
        nWorkDay++
      }
    }delete ptmStartDateTime;
    delete ptmEndDateTime;
      

  2.   

    总天数整除7以后乘以5.再加上最后几天中非星期六和星期天的天数.