boost之日期date_time

date_time库使用的日期基于格里高利历,支持从1400-01-01到9999-12-31的日期。

空的构造函数会创建一个值为not_a_date_time的无效日期;顺序传入年月日值则创建一个对应日期的date对象。

#include <iostream>
#define  BOOST_DATE_TIME_SOURCE
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
using namespace std;
using namespace boost;

int main()
{
	date d1;//无效的时间
	date d2(2013,8,15);//输入年月日
	date d3(2014,Aug,15);
	
	cout << to_iso_string(d2) <<endl;
	
	date d(2010,2,1);
	tm t = to_tm(d);//将date转换成tm结构
	date d2 =  date_from_tm(t)//从tm结构转换成date
	//只能转换年月日,时分秒为零
	return 0;
	
}
原文地址:https://www.cnblogs.com/liuweilinlin/p/3258970.html