有没有办法只得到no ?两个升压日期之间的工作日
在下面,我只得到日历日。
date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;
std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl;
也许最简单的方法是从头到尾运行day_iterator:
#include <iostream>
#include <boost/date_time.hpp>
int main()
{
using namespace boost::gregorian;
date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;
std::cout<<"calendar days between begin & end date are:" << duration << 'n';
int cnt=0;
for(day_iterator iter = begin_dt; iter!=end_dt; ++iter)
{
if( iter->day_of_week() != boost::date_time::Saturday
&& iter->day_of_week() != boost::date_time::Sunday)
++cnt;
}
std::cout << "of them " << cnt << " are weekdaysn";
}
您可以开始减去下一周开始的天数,并删除1或2取决于您是在周六或之前,还是周日。然后,您可以将剩余的天数除以7,将该数字乘以2,然后减去天数。你还得为剩下的部分找个理由。如果是6(星期六),你必须再移除一个。不容易,但你懂的。