当前本地时间高精度

 1 #include <chrono>
 2 void current_time()
 3 {
 4     // 当前时间点
 5     std::chrono::system_clock::time_point t_now =
 6         std::chrono::high_resolution_clock::now();
 7     // 转换精度到微秒级别
 8     std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> t_n = 
 9         std::chrono::time_point_cast<std::chrono::microseconds>(t_now);
10 
11     time_t nt = std::chrono::system_clock::to_time_t(t_now);
12     struct tm btm;
13 #ifdef _WIN32
14     localtime_s(&btm, &nt);
15 #else
16     localtime_r(&nt, &btm);
17 #endif
18 
19     char mbstr[256] = { 0 };
20     strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %H:%M:%S", &btm);
21     printf("%s.%06" PRIu64 "\n", mbstr, t_n.time_since_epoch() % 1000000);
22 }

 

转载于:https://www.cnblogs.com/suyunhong/p/9076532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值