提升月份的行为的原则是什么?
What is the principle for behavior of boost adding month?
boost添加月的示例
28/02/2009 1个月= 31/03/2009
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/gregorian/formatters.hpp>
#include <iostream>
using namespace boost::gregorian;
using namespace std;
int main()
{
typedef boost::date_time::month_functor<date> add_month;
date d(2019, Feb, 28);
add_month mf(1);
date d2 = d + mf.get_offset(d);
cout << to_simple_string(d2) << endl;//output:2019-Mar-31
}
输出是2019-MAR-31,而不是2019-MAR-28。这种行为的理论基础是什么?谈论它在C#和Delphi中输出2019-MAR-28,以获取类似的添加月份代码。
在 boost::date_time::month_functor
的文档中提到了此行为。
此调整功能为基于YMD的日历上的"基于月"的进步提供了逻辑。它用于处理不存在的一个月末日的政策是备份到本月的最后一天。也是,如果起始日期是一个月的最后一天,则该函数将尝试调整到月底。
因此,将一个月添加到2月28日将在3月31日导致。
但是将一个月添加到2月27日将在3月27日导致。
参见 LIVE DEMO.
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 通过JNI传递数据数组的最快方法是什么
- "using namespace std;"在C++的作用是什么?
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 提升月份的行为的原则是什么?
- 类实例和指针背后的Delphi设计原则是什么
- 在Visual Studio中组织C++代码的原则是什么?
- 在调用者内部扩展被调用者的指导原则是什么(内联-编译器优化)
- C++标准库的设计原则是什么?