cpp以毫秒级精度获取当前时刻的时间戳

首先获得当前时刻的时间点

std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>
      tp = std::chrono::time_point_cast<std::chrono::milliseconds>(
          std::chrono::system_clock::now());

再将时间点转换为时间戳形式

int timestamp = tp.time_since_epoch().count()

Reference

C++11获取时间戳和时间戳转日期(毫秒精度)_std::time_t-CSDN博客
C++ - 使用std::chrono获取当前秒级/毫秒级/微秒级/纳秒级时间戳_std获取当前时间-CSDN博客

posted @ 2023-10-25 17:22  pomolnc  阅读(251)  评论(0编辑  收藏  举报