c++ - Boost Date 回到过去

标签 c++ datetime boost

你好,我想使用 boost::Date_time 回到过去。例如,将日期设置为 10 天前的日期。我尝试使用 day_iterator 但到目前为止没有成功。 这是我的尝试:

boost::gregorian::date dateGenerator(int howManyDays)
{
    boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();

    boost::gregorian::date date(now.date());
    boost::gregorian::day_iterator dayIterator(data,-1);

    for (; howManyDays != 0; ++dayIterator)
    {
        howManyDays--;
    }
    return date;

}

感谢帮助

最佳答案

你可以减去一个date duration从使用 - operator 的日期开始:

date_duration dd(howManyDays);
date d2 = date - dd;
return d2;

关于c++ - Boost Date 回到过去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42026270/

相关文章:

c++ - 分离的线程在退出时崩溃

c# - DateTime.ParseExact 在 C# 中省略毫秒?

c++ - Boost正则表达式拆分遗漏了最后一个词

c++ - 使用 Boost.Asio 获取 "the whole packet"

c++ - 在 boost 的 multi_index_container 中获取不等于 x 的值

c++ - 为什么我的对象不能访问它自己的私有(private)成员变量? [C++]

c++ - 为什么不能用常量表达式声明数组?

c++ - 我可以将反向迭代器转换为正向迭代器吗?

java - 将 cron 表达式转换为漂亮的描述字符串?有 JAVA 和 Objective-C 的库吗?

MySQL - 将定时事件行转换为状态范围