c++获取当前时间的方法是什么
lewis
2017-08-10
19次阅读
在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()函数将时间点转换为时间戳。

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