#include <iostream>
#include <chrono>
int main() {
// 使用 std::chrono 获取当前时间戳(以毫秒为单位)
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
auto value = now_ms.time_since_epoch();
long long timestamp = value.count();
std::cout << "当前时间戳(毫秒): " << timestamp << std::endl;
return 0;
}
#include <iostream>
和 #include <chrono>
分别用于输入输出和时间处理。std::chrono::system_clock::now()
返回当前系统时间的时间点。std::chrono::time_point_cast<std::chrono::milliseconds>
将时间点转换为毫秒精度。time_since_epoch()
计算从纪元(通常是1970年1月1日)到当前时间的间隔。value.count()
将时间差转换为整数形式的时间戳。std::cout
输出当前时间戳。这个程序会输出当前时间的时间戳,单位是毫秒。
上一篇:c++ 串口通讯
下一篇:c++ 面向对象
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站