A simple question: do time(...)
and clock_gettime( CLOCK_REALTIME, ... )
produce the same time theoretically (in respect to seconds only)?
Here's what I mean:
time_t epoch;
time( &epoch );
and
struct timespec spec;
clock_gettime( CLOCK_REALTIME, &spec );
Are these two supposed to return exactly the same result (in respect to seconds)?
I "tested" this with changing time and time zones and epoch
and spec.tv_sec
always show the same result, but the documentation of CLOCK_REATIME
confuses me a bit and I'm not sure, that they will always be the same.
Real world situation: I have a piece of code, which uses time
. Now I want to have the time in milliseconds (which can be taken from spec.tv_nsec
, multiplied by 1000000). So I think about removing time
and using directly clock_gettime
, but I'm not sure if this will remain the same in all situations.
The question is somehow related to Measure time in Linux - time vs clock vs getrusage vs clock_gettime vs gettimeofday vs timespec_get? but the information there was not enough for me.. I think.