POCO库中文编程参考指南(6)Poco::Timestamp

简介: 1 类型别名 三个时间戳相关的类型别名,TimeDiff表示两个时间戳的差,第二个是以微秒为单位的时间戳,第三个是以 100 纳秒(0.1 微妙)为单位的时间戳: typedef Int64 TimeDiff; /// difference between two timestamps in...

1 类型别名

三个时间戳相关的类型别名,TimeDiff表示两个时间戳的差,第二个是以微秒为单位的时间戳,第三个是以 100 纳秒(0.1 微妙)为单位的时间戳:

typedef Int64 TimeDiff;   /// difference between two timestamps in microseconds
typedef Int64 TimeVal;    /// monotonic UTC time value in microsecond resolution
typedef Int64 UtcTimeVal; /// monotonic UTC time value in 100 nanosecond resolution

2 构造函数

当前时间的时间戳:

Timestamp();

指定时间的时间戳:

Timestamp(TimeVal tv);

拷贝构造函数:

Timestamp(const Timestamp& other);

3 重载运算符

赋值运算符:

Timestamp& operator = (const Timestamp& other);
Timestamp& operator = (TimeVal tv);

比较运算符:

bool operator == (const Timestamp& ts) const;
bool operator != (const Timestamp& ts) const;
bool operator >  (const Timestamp& ts) const;
bool operator >= (const Timestamp& ts) const;
bool operator <  (const Timestamp& ts) const;
bool operator <= (const Timestamp& ts) const;

算术运算符与算术赋值运算符

Timestamp  operator +  (TimeDiff d) const;
Timestamp  operator -  (TimeDiff d) const;
TimeDiff   operator -  (const Timestamp& ts) const;
Timestamp& operator += (TimeDiff d);
Timestamp& operator -= (TimeDiff d);

4 获取不同格式表示的时间戳

获取 std::time_t 格式的时间戳:

std::time_t epochTime() const;

获取 UTC-based time 格式的时间戳:

UtcTimeVal utcTime() const;

获取 TimeVal 格式(微秒)的时间戳:

TimeVal epochMicroseconds() const;

5 其他成员函数

交换时间戳:

void swap(Timestamp& timestamp);

更新时间戳为当前时间:

void update();

此时时间戳与这个时间戳的差(TimeStamp() - *this):

TimeDiff elapsed() const;

判断一段时间是否已经过去:

bool isElapsed(TimeDiff interval) const; 

6 静态成员函数

std::time_t对象创建一个Timestamp:

static Timestamp fromEpochTime(std::time_t t);

UtcTimeVal对象创建一个Timestamp

static Timestamp fromUtcTime(UtcTimeVal val);

返回时间解析度,即 Units per second。因为 Poco::TimeStamp 的最小解析度为微妙,所以该函数都返回 1000000:

static TimeVal resolution();

-

from:Blog.CSDN.net/Poechant

目录
相关文章
|
6天前
|
定位技术 Go 开发工具
dynamic-situational-awareness-qt学习记录
本文是作者yantuguiguziPGJ关于dynamic-situational-awareness-qt学习记录的分享,介绍了在Qt学习过程中发现的qml资源丰富的代码仓库,并提供了资源路径和相关的安装、配置步骤,涉及的内容有数字地球、GIS纹理等,同时提供了相关链接和git命令来克隆代码仓库和ArcGIS Runtime SDK for Qt的安装说明。
|
5月前
|
存储
【Qt 学习笔记】Qt 中出现乱码的解释及讨论
【Qt 学习笔记】Qt 中出现乱码的解释及讨论
269 0
|
XML 存储 边缘计算
Excelize 发布 2.7.1 版本,Go 语言 Excel 文档基础库
Excelize 是 Go 语言编写的用于操作 Office Excel 文档基础库,2023年4月10日,社区正式发布了 2.7.1 版本,该版本包含了多项新增功能、错误修复和兼容性提升优化。
145 3
Excelize 发布 2.7.1 版本,Go 语言 Excel 文档基础库
|
XML 网络协议 Linux
POCO库的安装与基础知识说明
一、POCO简单介绍 POCO(Portable Components)是一个轻量级的 C++ 类库,提供了许多基本的、可移植的 C++ 组件和工具。它包含了很多模块,例如网络、XML、加密、多线程等等,可帮助 C++ 开发人员快速构建高效、可靠、可扩展的应用程序。 1.1 基本模块 Foundation:提供了许多基本的 C++ 类和函数,例如字符串、文件、日期时间、异常处理、日志等等。 Net:提供了网络编程的支持,包括 TCP、UDP、HTTP、HTTPS、SMTP、POP3、FTP、DNS 等等。 Util:提供了各种工具和辅助函数,例如配置文件、命令行解析、正则表达式、JS
557 0
|
SQL 开发框架 安全
Go Web编程实战(10)----模板引擎库text/template包的使用
Go Web编程实战(10)----模板引擎库text/template包的使用
322 0
Go Web编程实战(10)----模板引擎库text/template包的使用
Qt实用技巧:VS2017编写纯C库以及使用Qt调用C库方法
Qt实用技巧:VS2017编写纯C库以及使用Qt调用C库方法
Qt实用技巧:VS2017编写纯C库以及使用Qt调用C库方法
在sublime text里阅读ABAP源代码的一些例子
在sublime text里阅读ABAP源代码的一些例子
122 0
在sublime text里阅读ABAP源代码的一些例子
|
边缘计算 测试技术 BI
Excelize 2.3.1 发布,Go 语言 Excel 文档基础库,支持加密表格文档
Excelize 2.3.1 发布,Go 语言 Excel 文档基础库,支持加密表格文档
607 3
Excelize 2.3.1 发布,Go 语言 Excel 文档基础库,支持加密表格文档
|
C++
POCO库中文编程参考指南(2)基本数据类型(Poco/Types.h)
POCO库中文编程参考指南(2)基本数据类型 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> @) 日期:April 14th, 2012 基本类型在Poco/Types.h头文件中。
1541 0