boost 日期操作的算法库

以下是算法你库的包含文件,一些操作函数在这些文件中定义声明
#include<boost/date_time.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
图片摘自网络
在这里插入图片描述

///测试时间
	typedef boost::posix_time::ptime ptime;
	using namespace boost::gregorian;
	//取当前时间
	ptime t(boost::posix_time::second_clock::local_time());

	//将时间格式转换成标准格式
	//YYYYMMDD
	std::string day_str1 = to_iso_string(t.date());
	//YYYY-MM-DD
	std::string day_str2 = to_iso_extended_string(t.date());
	//YYYYMMDDThhmmss
	std::string day_str3 = to_iso_string(t);
	//YYYY-MM-DDThhmmss
	std::string day_str4 = to_iso_extended_string(t);
	//hhmmss
	std::string day_str5 = to_iso_string(t.time_of_day());
	//hh::mm:ss
	std::string day_str12 = to_simple_string(t.time_of_day());
	//将ptime类型转换成tm类型
	tm tm_t = to_tm(t);
	//将tm类型转换成ptime类型的子类
	date new_today = date_from_tm(tm_t);
	assert(new_today == t.date());

	//日期加减
	date sp(2013, 3, 31);
	std::string day_str6 = to_iso_extended_string(sp);
	sp += days(1);
	std::string day_str7 = to_iso_extended_string(sp);
	using namespace boost::posix_time;
	//时间加减
	time_duration spp(23, 59, 31);
	spp += seconds(65);
	auto kkk=spp.hours();
	std::string day_str11 = to_simple_string(spp);

	//将标准格式化字符串转成ptime
	ptime day_str8 = time_from_string("2016-06-15 17:00:00");
	ptime day_str10 = time_from_string("2016-06-18 17:00:00");

	date day_str9 = from_string("2016-06-15");
	date_duration dd = t.date() - day_str9;
	int numm = dd.days();
	//time_duration tt =  day_str8- day_str10;
	//int numm2 = tt.seconds();

	//判断大小
	bool result = day_str10.date() > t.date();
	bool result2 = day_str10.date() < t.date();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值