Android NDK计时年代不正确(std :: chrono :: high_resolution_clock) [英] Android NDK chrono epoch is not correct (std::chrono::high_resolution_clock)
问题描述
下面的代码不打印纪元.
The code below does not print epoch.
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::milliseconds Milliseconds;
auto res = std::chrono::duration_cast<Milliseconds>(Clock::now().time_since_epoch()).count();
std::stringstream ss;
ss << res;
printf(">>>>>>>>>>> TimeUtiles::getTimestamp %s", ss.str().c_str());
我使用NDK r9d,选择的NDK工具链版本为4.8!
I use NDK r9d and selected NDK toolchain version was 4.8 !
将std::chrono::high_resolution_clock
更改为std::chrono::system_clock
并起作用.为什么?
Changed std::chrono::high_resolution_clock
to std::chrono::system_clock
and it worked. Why?
推荐答案
system_clock
就像一块手表(智能手机占领地球之前,腕上的东西).它可以告诉您一天中的时间.而且由于没有一个时钟能保持完美的时间,它有时会问另一个时钟是什么时间,并且对其自身进行微小的调整以保持准确.
system_clock
is like a watch (the thing on your wrist before smart phones took over the planet). It can tell you the time of day. And because no clock keeps perfect time, it sometimes asks another clock what time it is and makes tiny adjustments to itself to stay accurate.
steady_clock
就像秒表.这对计时跑步者一圈或计时您的功能非常有用.它从不进行自我调整,而是尽力将每秒的秒数标记为最佳.但它不知道一天中的什么时间,甚至一年中的哪一天.
steady_clock
is like a stopwatch. It is great for timing a runner on a lap, or timing your function. It never adjusts itself, but strives to mark one second per second as best it can. But it has no idea what the time of day is, or even what day of the year.
high_resolution_clock
也与任何人类日历或时间系统无关,并且可以是system_clock
或steady_clock
的typedef
.实际上,它始终是这些时钟之一的typedef
.
high_resolution_clock
also has no relationship to any human calendar or time system, and is allowed to be a typedef
to either system_clock
or steady_clock
. And in practice, it always is a typedef
to one of these clocks.
在您的系统上,high_resolution_clock
显然与steady_clock
相同.
On your system, high_resolution_clock
is evidently the same type as steady_clock
.
这篇关于Android NDK计时年代不正确(std :: chrono :: high_resolution_clock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!