Poco::Timestamp 提供了高精度的時間戳功能,支持微秒(TimeVal)和百納秒(UtcTimeVal)兩種分辨率,適用於性能測量、日誌記錄等場景。
typedef Int64 TimeDiff; // 兩個時間戳之差,單位:微秒
typedef Int64 TimeVal; // 單調 UTC 時間,微秒分辨率
typedef Int64 UtcTimeVal; // 單調 UTC 時間,百納秒分辨率 (0.1 微秒)
Timestamp():創建當前時間的時間戳。Timestamp(TimeVal tv):從指定的微秒值創建。Timestamp(const Timestamp& other):拷貝構造。Timestamp& operator = (const Timestamp& other)Timestamp& operator = (TimeVal tv)==, !=, >, >=, <, <=:支持時間戳之間的全關係比較。Timestamp operator + (TimeDiff d) const:加上時間差。Timestamp operator - (TimeDiff d) const:減去時間差。TimeDiff operator - (const Timestamp& ts) const:計算兩時間戳之差。Timestamp& operator += (TimeDiff d)、operator -= (TimeDiff d):複合賦值。std::time_t epochTime() const:獲取 std::time_t 格式(秒級)。UtcTimeVal utcTime() const:獲取 UTC 時間(百納秒)。TimeVal epochMicroseconds() const:獲取微秒級時間值。void swap(Timestamp& timestamp):交換兩個時間戳。void update():更新為當前時間。TimeDiff elapsed() const:返回從該時間戳到現在經過的微秒數。bool isElapsed(TimeDiff interval) const:判斷指定間隔是否已過。static Timestamp fromEpochTime(std::time_t t):從 time_t 創建。static Timestamp fromUtcTime(UtcTimeVal val):從 UTC 時間值創建。static TimeVal resolution():返回時間分辨率(每秒單位數),固定返回 1,000,000(微秒級)。轉載請注明來自柳大的 CSDN 博客:Blog.CSDN.net/Poechant