工作日“时间使用boost日期 [英] weekdays' duration using boost date
本文介绍了工作日“时间使用boost日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法只得到了否定的。 2升压日期之间的工作日。
在下面,我只得到日历天。
日期begin_dt(2011年8月,3);
日期END_DT(day_clock :: local_day());
天期限= END_DT,begin_dt;性病::法院LT&;<开头与放大器之间的日历天;结束日期是:<<持续时间LT;<的std :: ENDL;
解决方案
也许最简单的方法是运行从开始day_iterator完成:
的#include<&iostream的GT;
#包括LT&;升压/ date_time.hpp>
诠释的main()
{
使用空间boost ::格利高; 日期begin_dt(2011年8月,3);
日期END_DT(day_clock :: local_day());
天期限= END_DT,begin_dt; 性病::法院LT&;<开头与放大器之间的日历天;结束日期是:<<持续时间LT;<的'\\ n'; INT CNT = 0;
对于(ITER day_iterator = begin_dt;!ITER = END_DT ++ ITER)
{
如果(iter-> DAY_OF_WEEK()=提振:: DATE_TIME ::周六!
&功放;&安培; iter->!DAY_OF_WEEK()=提振:: DATE_TIME ::星期日)
++ CNT;
}
性病::法院LT&;< 他们的<< CNT<< 都是平日的\\ n;
}
Is there a way to get only the no. of weekdays between 2 boost dates.
In the following, I'm only getting calendar days.
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;
解决方案
Perhaps the simplest way is to run a day_iterator from start to finish:
#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";
}
这篇关于工作日“时间使用boost日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文