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

POCO库中文编程参考指南(6)Poco::Timestamp的更多相关文章

  1. POCO库中文编程参考指南(4)Poco::Net::IPAddress

    POCO库中文编程参考指南(4)Poco::Net::IPAddress 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmai ...

  2. POCO库中文编程参考指南(3)Poco::Net::Socket

    POCO库中文编程参考指南(3)Poco::Net::Socket 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.c ...

  3. POCO库中文编程参考指南(2)基本数据类型(Poco/Types.h)

    POCO库中文编程参考指南(2)基本数据类型 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> ...

  4. POCO库中文编程参考指南(1)总览

    POCO库中文编程参考指南(1)总览 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# -> @) ...

  5. POCO库中文编程参考指南(11)如何使用Reactor框架?

    1 Reactor 框架概述 POCO 中的 Reactor 框架是基于 Reactor 设计模式进行设计的.其中由 Handler 将某 Socket 产生的事件,发送到指定的对象的方法上,作为回调 ...

  6. POCO库中文编程参考指南(8)丰富的Socket编程

    POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...

  7. POCO库中文编程参考指南(10)如何使用TCPServer框架?

    1 TCPServer 框架概述 POCO 库提供TCPServer框架,用以搭建自定义的 TCP 服务器.TCPServer维护一个连接队列.一个连接线程池.连接线程用于处理连接,连接线程只要一空闲 ...

  8. POCO库中文编程参考指南(9)Poco::Net::DNS

    1 Poco::Net::DNS namespace Poco { namespace Net { class Net_API DNS { public: static HostEntry hostB ...

  9. POCO库中文编程参考指南(5)Poco::Net::SocketAddress

    1 枚举 最大地址长度,这个与Poco::Net::IPAddress中的定义可以类比,不过这里指的是`struct sockaddr_in6 enum { MAX_ADDRESS_LENGTH = ...

随机推荐

  1. 笔记-unittest实战

    笔记-unittest实战 1.      框架图 2.      用例 编写自己的测试用例类,继承于基类 class ApiTestCase(unittest.TestCase): setUp方法会 ...

  2. Hive数据导入导出的n种方式

    Tutorial-LoadingData Hive加载数据的6种方式 #格式 load data [local] inpath '/op/datas/xxx.txt' [overwrite] into ...

  3. web在线调试

    xx <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta h ...

  4. 牛客练习赛22-E.简单数据结构1(扩展欧拉定理降幂 +树状数组)

    链接:E.简单数据结构1 题意: 给一个长为n的序列,m次操作,每次操作: 1.区间加 2.对于区间,查询 ,一直到- 请注意每次的模数不同.   题解:扩展欧拉定理降幂 对一个数p取log(p)次的 ...

  5. [转]LVS+Keepalived负载均衡配置

    简介 来源:https://www.cnblogs.com/MacoLee/p/5858995.html lvs一般是和keepalived一起组合使用的,虽然也可以单独使用lvs,但配置比较繁琐,且 ...

  6. ssh-debian87.sh

    #!/bin/bash sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config s ...

  7. Python MySQLdb 模块使用方法

    import MySQLdb 2.和数据库建立连接 conn=MySQLdb.connect(host="localhost",user="root",pass ...

  8. C#共享内存

    百度:C#共享内存. 文章:C# .Net 多进程同步 通信 共享内存 内存映射文件 Memory Mapped 转 资料:UnmanagedMemoryAccessor 资料:MemoryMappe ...

  9. B-Tree索引和Hash索引的区别

    Hash 索引结构的特殊性,其检索效率非常高,索引的检索可以一次定位,不像B-Tree 索引需要从根节点到枝节点,最后才能访问到页节点这样多次的IO访问,所以 Hash 索引的查询效率要远高于 B-T ...

  10. Scala 基础(4)—— 类和对象

    1. 类.字段和方法 Scala 用 class 关键字定义类,一旦定义好一个类,就可以使用 new 关键字创建对象. Scala 使用 new 调用无参构造器时,可以不使用 (),推荐不使用括号: ...