Android NDK chrono epoch is not correct (std::chrono::high_resolution_clock)

蹲街弑〆低调 提交于 2020-01-03 07:15:10

问题


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());

I use NDK r9d and selected NDK toolchain version was 4.8 !

EDIT:

Changed std::chrono::high_resolution_clock to std::chrono::system_clockand it worked. Why?


回答1:


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 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 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.

On your system, high_resolution_clock is evidently the same type as steady_clock.



来源:https://stackoverflow.com/questions/29005351/android-ndk-chrono-epoch-is-not-correct-stdchronohigh-resolution-clock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!