有没有办法只获取号码。两个 boost 日期之间的工作日。
在下文中,我仅获取日历日。
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 weekdays\n";
}
关于c++ - 使用 boost 日期的工作日持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7340986/