Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::chrono default duration for time_since_epoch

Tags:

c++

c++11

chrono

If I have the following clock and use it to get a count of ticks since the clock's epoch, what does this count actually represent.

std::chrono::high_resolution_clock::now().time_since_epoch().count();

For instance I just ran this and got 1389375799048790227. What does this number mean? Is it nanoseconds, microseconds, etc?

like image 820
Sean Lynch Avatar asked Jan 10 '14 17:01

Sean Lynch


People also ask

What is std :: Chrono :: duration?

Class template std::chrono::duration represents a time interval. It consists of a count of ticks of type Rep and a tick period, where the tick period is a compile-time rational fraction representing the time in seconds from one tick to the next. The only data stored in a duration is a tick count of type Rep .

What is time since epoch C++?

Time since epoch. Returns a duration object with the time span value between the epoch and the time point. The value returned is the current value of the internal duration object.

What is std :: Chrono :: Time_point?

Class template std::chrono::time_point represents a point in time. It is implemented as if it stores a value of type Duration indicating the time interval from the start of the Clock 's epoch. Clock must meet the requirements for Clock or be std::chrono::local_t (since C++20).

What is clock's epoch?

In a computing context, an epoch is the date and time relative to which a computer's clock and timestamp values are determined. The epoch traditionally corresponds to 0 hours, 0 minutes, and 0 seconds (00:00:00) Coordinated Universal Time (UTC) on a specific date, which varies from system to system.


1 Answers

The type of the duration is std::chrono::high_resolution_clock::duration. You can inspect a duration's tick period with: std::chrono::high_resolution_clock::duration::period::num and std::chrono::high_resolution_clock::duration::period::den. This is the numerator and denominator of a fraction representing the amount of seconds per tick (e.g. 1/1000000000 for nanoseconds).

The epoch is unspecified, but for you is 1389375799048790227 ticks from when you got that result.

like image 170
Howard Hinnant Avatar answered Oct 05 '22 11:10

Howard Hinnant