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();
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2013-09-29 C/C++代码静态检查工具Cppcheck在VS2008开发环境中的安装配置和使用
2013-09-29 MFC上下浮动与渐入渐出消息提示框实现
2013-09-29 MFC渐入渐出框实现方式二
2013-09-29 Cppcheck软件使用