date_time组件简单涉及

 
#include <iostream>
#define BOOST_DATE_TIME_SOURCE
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace std;
using namespace boost::gregorian;
int main(){
	date d1(2012,12,21);//直接构造
	date d2(2012,Jan,1);
	date d3; //无效日期
	date d4(d2);//复制构造函数
	cout << "d1:" << d1 << endl  //输出
		 << "d2:" << d2 << endl
		 << "d3:" << d3 << endl
		 << "d4:" << d4 << endl
		 << "local_day:" << day_clock::local_day() << endl //本地时间
		 << "universal_day:" << day_clock::universal_day() << endl;
	date d5(max_date_time); //最大时间
	date d6(min_date_time); //最小时间
	date d7(neg_infin); //负无穷日期
	date d8(pos_infin); //正无穷日期
	cout << "d5:" << d5 << endl
		 << "d6:" << d6 << endl
		 << "d7:" << d7 << endl
		 << "d8:" << d8 << endl;
	date d9 = from_undelimited_string("19901019"); //直接把字符串转换成特定日期格式
	cout << "d9:" << d9 << endl;
	date d10(1990,12,06);
	//string date_str = to_simple_string(d10);
	//cout << date_str << endl;
	//cout << to_iso_string(d10) << endl
		// << to_iso_extended_string(d10) << endl;
	cout << "d10:" << d10 << endl;
}


运行结果:

d1:2012-Dec-21
d2:2012-Jan-01
d3:not-a-date-time
d4:2012-Jan-01
local_day:2012-Mar-12
universal_day:2012-Mar-12
d5:9999-Dec-31
d6:1400-Jan-01
d7:-infinity
d8:+infinity
d9:1990-Oct-19
d10:1990-Dec-06

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值