I am trying to see whether my data is 120 second old or not by looking at the timestamp of the data so I have below code:
uint64_t now = duration_cast
The reason you're seeing a positive value is due to the unsigned integer wrap-around. Try this and see:
std::cout << static_cast (-1) << std::endl;
Is the value returned by getTimestamp()
expected? If not, it's a little hard to see what's wrong, without seeing the implementation of getTimestamp()
. It looks like the timestamp was not measured using the same clock.
The steady clock is best for measuring time intervals. To quote from cppreference.com:
Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward. This clock is not related to wall clock time, and is best suitable for measuring intervals.
As opposed to the system_clock, which is not monotonic (i.e. the time can decrease if, say, the user changes the time on the host machine.)