在C++11中,可以使用std::chrono库来获取系统时间戳。以下是一个示例代码:

#include <iostream>
#include <chrono>

int main() {
    // 获取当前时间点
    auto now = std::chrono::system_clock::now();

    // 转换为时间戳(以秒为单位)
    auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();

    std::cout << "当前时间戳为:" << timestamp << "秒" << std::endl;

    return 0;
}

上述代码中,std::chrono::system_clock::now()返回当前系统时间点,然后使用std::chrono::duration_cast将时间间隔转换为以秒为单位的时间戳。最后,通过count()函数获取时间戳的数值

c++11 获取系统时间戳

原文地址: https://www.cveoy.top/t/topic/irHm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录