Linux 拨号vps windows公众号手机端

c++获取当前时间的方法是什么

lewis 8年前 (2017-08-10) 阅读数 6 #程序编程
文章标签 c++

在C++中,可以使用std::chrono库来获取当前时间。

下面是一个使用std::chrono库获取当前时间的例子:

#include <iostream>
#include <chrono>

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

    // 将时间点转换为时间戳
    auto timestamp = std::chrono::system_clock::to_time_t(now);

    // 输出时间戳
    std::cout << "当前时间的时间戳:" << timestamp << std::endl;

    return 0;
}

在上面的例子中,std::chrono::system_clock::now()函数可以获取当前时间点,然后可以使用std::chrono::system_clock::to_time_t()函数将时间点转换为时间戳。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门