c++ - 使用 boost 日期的工作日持续时间

标签 c++ boost boost-date-time

有没有办法只获取号码。两个 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/

相关文章:

c++ - 获取指向 boost::any::operator= 的指针

c++ - 从时间 std::strings boost ptime

c++ - 使用 boost::date,我如何计算 "last Monday"?

C++ boost::posix_time::ptime 默认值

c++ - 将两个充满数字的文件组合成第三个排序文件。文件名和 cin 的问题

c++ - Boost 与 asio::placeholders::error 绑定(bind)

c++ - 在 boost::asio 服务器中使用 p12 容器

c++ - 如何将字符数组转换为基于字符串的十六进制流 (ostringstream)

python - 编译 lunatic-python 时出错

c++ - 使用正则表达式验证电子邮件和电话字段 Qt