Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is gettimeofday() equivalent in c++11

Probably duplicate, but What is gettimeofday() equivalent in c++11 ?

I am trying to get 64 bit timestamp with microseconds, similar to Java / Python.

like image 595
Nick Avatar asked Dec 30 '25 01:12

Nick


2 Answers

Use std::chrono::system_clock::now().

UPDATE

You can check the necessary minimal precision by this static assert:

static_assert (std::ratio_less_equal<std::chrono::system_clock::duration::period,
    std::ratio<1,100> >::value, "");
like image 85
wilx Avatar answered Dec 31 '25 13:12

wilx


To get the highest resolution supported by your system, use std::high_resolution_clock::now. The high-resolution clock may be an alias for std::chrono::system_clock.

like image 26
Konrad Rudolph Avatar answered Dec 31 '25 14:12

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!