Boost库学习随记二 date_time、time_duration、date_facet、time_facet、timer库示例等:

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情
//"Boost_data_Timer.h"头文件

#ifndef BOOST_TEST 
#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"
//date_time库的时间功能位于名字空间boost::posix_time,为了使用时间组件,需要
//包含头文件<boost/date_time/posix_time/posix_time.hpp>即
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost::posix_time;


#endif // !BOOST_TEST 


//"Boost_data_Timer.cpp"

#include <iostream>
#include <cassert>
//#include <Windows.h>
//#include <windef.h>
#include "Boost_data_Timer.h"
using namespace boost;
using namespace std;



//使用date_time日期功能需要包含gregorian.hpp,并声明命名空间。
using namespace boost::gregorian; 

//日期处理测试示例
bool test_date_time()
{
	//date赋值的几种方式
	
		date d1;
		date d2(2010, 1, 1);
		date d3(2000, Jan, 1);
		date d4(d2);
	


	//从字符串产生赋值
	{
	date dd1 = from_string("1999-12-31");
	date dd2 = from_string("2005/1/1");
	date dd3 = from_undelimited_string("20000101");
	//枚举类型特殊时间,超出范围值会报异常。
	date ddd1(neg_infin);  //负无限日期
	date ddd2(pos_infin);  //正无限日期
	date ddd3(not_a_date_time);	//无效日期
	date ddd4(max_date_time);//最大可能日期9999-12031 :)万年虫有没有?
	date ddd5(min_date_time);//最小可能日期1400-01-01

	assert(d1 == date(not_a_date_time));
	assert(d2 == d4);
	assert(d3 < d4);

	}
	
	//auto类型转换时的测试
	if (d2.is_infinity()) //是否为一个无限日期
	{
		auto y = d2.year();
		auto m = d2.month();
		auto d = d2.day();
		cout << y << endl;
		cout << m << endl;
		cout << d << endl;
		cout << d2.year() << endl;
	}
	
	date::ymd_type ymd = d2.year_month_day();
	if (ymd.day)
	{
		auto y = ymd.year;
		auto m = ymd.month;
		auto d = ymd.day;
		cout << y << endl;
		cout << m << endl;
		cout << d << endl;
		//测试auto类型转换
		int a = y;
		cout << a << endl;
		//直接输出ymd
		cout << ymd.year << ymd.month << ymd.day << endl;
	}

	{
		//day_of_week星期数
		date dd2(2010, 01, 01), dd3(2011, 12, 12);
		auto a = dd2.day_of_week();
		cout << "dd2.day_of_week: " << dd2.day_of_week() << endl;
		//day_of_year当年的第几天
		cout << "dd2.day_of_year:" << dd2.day_of_year() << endl;
		//end_of_month返回当月最后一天date对象
		auto b = dd2.end_of_month();
		cout << b.year() << b.month() << b.day() << endl;
		cout << "dd2.end_of_month:" << b.day() << endl;

		//week_number 返回date所在的周是当年的第几周范围0-53
		cout << "week_number: " << dd3.week_number() << endl;
	}

	//is_xxxx相关函数测试
	{
		//is_infinity()			是否是一个无限日期
		//is_neg_infinity()     是否是一个负无限日期
		//is_pos_infinity()     是否是一个正无限日期
		//is_not_a_date()       是否是一个无效日期
		//is_special()          是否是任意一个特殊日期
		assert(date(pos_infin).is_infinity());
		assert(date(pos_infin).is_pos_infinity());
		assert(date(neg_infin).is_neg_infinity());
		assert(date(not_a_date_time).is_not_a_date());
		assert(date(not_a_date_time).is_special());
		assert(!date(2010, 10, 1).is_special(
Boost日期时间处理(date_time) 概述 使用date_time需要在编译时加上"-lboost_date_time",而且需要包含以下头文件: 处理日期的组件:#include 处理时间的组件:#include datedatedate_time处理日期的核心类,使用一个32位的整数作为内部存储,以天为单位表示时间点概念。date也全面支持比较操作输入输入出,我们可以完全把它当成一个像int、st 阅读详情

相关推荐

BOOST C++ 10 】(4)时间格式输出(11-12)【改进中..】

本章到目前为止描述的示例程序以 2014-May-12 格式写入结果。 Boost.DateTime 允许您以不同的格式显示结果。日历日期时间可以使用 boost::date_time::date_facet boost::date_time::time_facet 格式化。

gongdiwudu的专栏 4612

boostdate_time源码解析

fill:#333;stroke:1;fill:none;important;important;important;important;important;important;important;important;important;important;important;important;important;important;important;important;

多看多听多总结 533

fatal error: boost/format.hpp: No such file or directory

在读高博的《视觉SLAM十四讲》的第五章内容,运行rgbd的joinMap.cpp时报错 fatal error: boost/format.hpp: No such file or directory 解决方案: sudo apt-get install libboost1.62-all-dev (方法很暴力,很无脑,若有更合适的解决方法还请各位指教!) ...

~勿据散客~的博客 4930

编译boost程序出现如下错误fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_54.lib'的解决方法

对于如下程序: #include #include #include using namespace std; int main() { boost::asio::io_service io; boost::asio::deadline_timer t(io, boost::posix_time::seconds(5)); t.wait(); cout << "Hell

Second的专栏 5759

boost/date_time/posix_time及chrono高精度计时详细总结

本文主要介绍了及时器相关的time_duration、ptimetime_period、ticks、microsec_clock::local_time()、not_a_date_time、等的用法总结。

zxy_ZXY123的博客 1321

boost ptime转化为时间字符串

//对象的定义 boost::posix_time::ptime p(boost::gregorian::date(2010, 3, 5)); //2010年3月5号0点 boost::posix_time::ptime p1(boost::gregorian::date(2010, 3, 5), boost::posix_time::hours(1)); //2010年3月5号1点 boost::posix_time::ptime p2 = boost::posix_tim...

qq_23350817的博客 3689

boost日期格式互转time_t互转

boost日期虽然强大,使用起来不太方便,在此记录下日期转换代码。 boost日期格式转换代码如下: bool FromString(boost::posix_time::ptime&amp; pt, std::string datetime, std::string format) { std::stringstream ss(datetime); //std::loc...

豪哥专栏 4375

c# DataTime

C# DateTime 获得当前系统时间DateTime dt = DateTime.Now; Environment.TickCount可以得到“系统启动到现在”的毫秒值 DateTime now = DateTime.Now; Console.WriteLine(now.ToString("yyyy-MM-dd"));  //按yyyy-MM-dd格式输出s Console.

944

DenseNetYolo模型在ultra96开发板上的实现

find -print0表示在find的每一个结果之后加一个NULL字符,而不是默认加一个换行符。然后xargs -0表示xargs用NULL来作为分隔符。 https://www.cnblogs.com/liuyihua1992/p/9689314.html john@john-wang:~/Vitis-AI_1.2/YOLOv3$ sudo apt-get install dos2unix sudo apt-get install libopencv-dev john@john-wang:~/Viti.

u010879745的博客 3983

boost准模板time_duration类的使用

# define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG #define BOOST_ALL_NO_LIB #include #include using namespace std; using namespace boost::posix_time; int main() { time_duration td(1,10,20,1000);//定义一个时

onlysingleboy的专栏 1998

boost 时间日期处理

导视: 类 特点 缺点 说明 timer 计时基类 不适合大跨度时间 适用大部分的普通计时 progress_timer 继承自timer 可以自动写入流中 只精确到0.01s 如果需要更精确,可派生个类,调用stream的precision设置

阿修罗道 1万+

Boost日期时间date_time)—时间

目录 一、基本介绍 时间长度 三、时间精确度 四、时间点(ptime)-基本介绍 五、时间点(ptime)-对象创建 六、时间点(ptime)-基本运用 七、时间区间 八、时间迭代器-个人认为这个用处还比较多 九、扩展-高精度计时器 一、基本介绍 引入头文件:#include <boost/date_time/posix_time/posix_time.hpp> 时间长度 int main(int argc, char **argv) { // 创建时间长度,

红尘客的博客 3503

boost完全开发指南第2章-处理时间 6 (time_duration时间长度的使用)

1、使用time_duration类需要声明#include using namespace boost::posix_time; 一般都是精确到微秒级,但是 ,如果在以上声明前定义宏BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG,可以精确到纳秒级。 2、time_duration的子类有:hours、minutes、seconds、millisec/millis

学习,思考,记录 4013

Golang 中的 time 包详解():time.Duration

在日常开发过程中,会频繁遇到对时间进行操作的场景,使用 Golang 中的 time 包可以很方便地实现对时间的相关操作。接下来的几篇文章会详细讲解 time 包,本文讲解一下 time 包中的 time.Duration 类型。

路多辛的所思所想 3940

[BOOST]时间日期

处理时间 时间长度 boost 时间长度time_duration类,类似C中tm结构的时分秒部分。 #include &amp;lt;boost/date_time/posix_time/posix_time.hpp&amp;gt; using namespace boost::posix_time; time_duration td(1,10,30,1000);// 1小时10分30秒1毫秒 h...

Zhihuitech 635

boost实现日期时间格式化

boost实现日期时间格式化

Ran 5013
上一篇: Boost库学习随记一 timer库示例:
下一篇: 智能指针auto_ptr
动起手来实现白日梦
博客等级 码龄20年 0粉丝 48原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值