boost库之date

1.date
// date_Exam.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

#define BOOST_DATE_TIME_SOURCE
#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 "libs/date_time/src/gregorian/gregorian_types.cpp"

#include "boost/date_time/gregorian/conversion.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"

using namespace boost::gregorian;
int _tmain(int argc, _TCHAR* argv[])
{
	
	date d1;
	date d2(2012, 5, 4);
	
	std::cout << d1.is_not_a_date() << std::endl;
	std::cout << d1.is_infinity() << std::endl;
	std::cout << d1.is_neg_infinity() << std::endl;
	std::cout << d1.is_pos_infinity() << std::endl;
	std::cout << d1.is_special() << std::endl;

	std::cout << d2.year() << std::endl;
	std::cout << d2.month() << std::endl;
	std::cout << d2.day() << std::endl;

	std::cout << to_simple_string(d2) << std::endl;
	std::cout << to_iso_string(d2) << std::endl;
	std::cout << to_iso_extended_string(d2) << std::endl;

	tm t = to_tm(d2);
	date d3 =  date_from_tm(t);
	
	//时间长度
	date_duration dd(1);
	date d4(2008, 1, 1);
	d4 = d4 + dd;
	std::cout << to_simple_string(d4) << std::endl;

	years y1(10);
	d4 = d4 + y1;
	std::cout << to_simple_string(d4) << std::endl;

	//日期区间
	date_period dp1(d4, days(10));

	
	return 0;
}

2.time_duration

// posix_time_Exam.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"
#include <iostream>

#define BOOST_DATE_TIME_SOURCE
#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 "libs/date_time/src/gregorian/gregorian_types.cpp"

#include "boost/date_time/gregorian/conversion.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"

#include "boost/date_time/posix_time/posix_time.hpp"
using namespace boost::posix_time;

int _tmain(int argc, _TCHAR* argv[])
{	
	// 时间长度
	time_duration td(1, 10, 30, 1000);
	hours h(1);
	minutes m(10);
	seconds s(30);
	millisec ms(1);
	time_duration td1 = h + m + s + ms;

	time_duration td2 = duration_from_string("1:10:30:001");

	std::cout << td.total_microseconds() << std::endl;
	std::cout << td1.total_microseconds() << std::endl;
	std::cout << td2.total_microseconds() << std::endl;

	// 时间点
	using namespace boost::gregorian;
	ptime p(date(2010, 3, 5), hours(1));
	std::cout << p << std::endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值