# POCO库中文编程参考指南（6）Poco::Timestamp

• 作者：柳大·Poechant
• 博客：Blog.CSDN.net/Poechant
• 邮箱：zhongchao.ustc#gmail.com (# -> @)
• 日期：April 15th, 2012

## 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 epochTime() const;
``````

``````UtcTimeVal utcTime() const;
``````

``````TimeVal epochMicroseconds() const;
``````

## 5 其他成员函数

``````void swap(Timestamp& timestamp);
``````

``````void update();
``````

``````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);
``````

``````static TimeVal resolution();
``````

-

-