Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 771
Narek Avatar asked Mar 12 '15 08:03

Narek


1 Answers

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.

like image 148
Howard Hinnant Avatar answered Oct 17 '22 15:10

Howard Hinnant