C++ POCO库中文编程参考指南(6) Poco::Timestamp
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 ();
转载请著名来自柳大的CSDN博客: Blog.CSDN.net/Poechant
查察全套文章:http://www.bianceng.cn/Programming/cplus/201301/35022.htm