Reputation: 28178
Can calling system_clock::now() in the future give a time in the past? For example, because of daylight savings time?
What about calling system_clock::now().time_since_epoch()? Or is it guaranteed to always return later and later time points? Even without a guarantee, do all implementations do it a certain way in practice (if so, how)?
Upvotes: 3
Views: 248
Reputation: 3529
std::chrono
offers both system_clock
and steady_clock
for general-purpose time tracking.
The system_clock
class will rely entirely on the platform and thus if a user were to change the system time (or NTP etc.) it will obviously send you into the past/future. User changing timezone will not affect you providing you're not using local time.
steady_clock
on the other hand is completely consistent (although VS2013 misimplemented this and it behaves just like system_clock
, sadly)
Thus, if you need to know absolute time rather than simply the passing of time, I would suggest that you grab a value from system_clock
at startup and use steady_clock
from that point onwards.
Upvotes: 2