【问题标题】:How to get each individual date between two boost ptime's如何在两个提升 ptime 之间获取每个单独的日期
【发布时间】:2015-08-02 23:40:18
【问题描述】:

我有两个 boost ptime 的 time_from 和 time_to 我想找到这两个时间之间的每个日期,我最初是这样做的

const auto date_duration(time_to.date() - time_from.date());
for(int i = 0; i < date_duration.days(); ++i)
{
    time_from.date() + boost::gregorian::days(i);
}

我在想如果存储在循环中计算的日期会给我两次之间的每个日期,但是它不起作用,因为这给了我两次之间的天数,而不是两次之间的每个单独的日期,我想知道是否有人知道获得这个的最佳方法?

【问题讨论】:

    标签: c++ date boost boost-date-time


    【解决方案1】:

    试试这个:

    day_iterator itr(time_from.date());
    while (itr <= time_to.date()) {
      std::cout << (*itr) << std::endl;
      ++itr;
    }
    

    【讨论】:

    • 谢谢你,正是我需要的!!
    猜你喜欢
    • 1970-01-01
    • 2019-03-24
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多