//时间间隔问题
#define BOOST_DATE_TIME_SOURCE
/*#define BOOST_DATE_TIME_SOIURCE #define BOOST_DATE_TIME_NO_LIB或者#BOOST_ALL_NO_LIB
这些宏定义指明项目对于boost库是源代码级别的引入,将boost库源代码直接嵌入到工程中,不加的话默认找编译后的boost库文件
*/
#include<iostream>
#include<libs/date_time/src/gregorian/greg_names.hpp>
#include<libs/date_time/src/gregorian/date_generators.cpp>
#include<libs/date_time/src/gregorian/greg_month.cpp>
#include<libs/date_time/src/gregorian/greg_weekday.cpp>
#include<boost/date_time/gregorian/gregorian.hpp>
using namespace std;
using namespace boost::gregorian;
int main()
{
//date_period构造函数
date_period dp1(date(1993,5,1),days(100) );//日期后多少天
//date_period dp2(date(1993,5,1),years(23));不能用months和years
date_period dp3(date(2010,8,25),date(day_clock::local_day()));//两个日期间的间隔
//如果days()的参数为负 或者 第一个date()在第二个date()后,则对象无效
cout<<dp1.is_null()<<endl;//是否是无效时间段
cout<<dp1.begin()<<endl;//时间段开始日期
cout<<dp1.last()<<endl;//时间段最后一个日期
cout<<dp1.end()<<endl;//时间段后的第一个日期
cout<<dp1.length().days()<<endl;//时间段的长度
//默认输出
cout<<dp1<<endl;
//date_period比较,比较两个时间段在时间轴上的位置关系,如果两个时间段有交叉或者包含,比较无意义
cout<<(dp1>dp3)<<endl;//时间段靠后的大
getchar();
}
上面是对date_period的基本使用,下图是运行结果: