[Cialug] Seconds only timestamp

Jeffrey Ollie jeff at ocjtech.us
Wed Jun 18 14:51:19 CDT 2014


On Wed, Jun 18, 2014 at 2:37 PM, Brian Wood <woodbrian77 at gmail.com> wrote:
> From: Paul Gray
>
>> gettimeofday would be my goto call for just seconds (since epoch).
>
> I think gettimeofday would also be giving more info than I need.
>
> "The gettimeofday() function shall obtain the current  time,  expressed  as
>        seconds  and  microseconds  since  the  Epoch"
>
> The best I've found so far is to use the CLOCK_REALTIME_COARSE
> flag.

gettimeofday returns a struct timeval, which has seconds and
microseconds. clock_gettime (which I'm assuming is what you use with
CLOCK_REALTIME_COARSE) returns a struct timespec which contains
seconds and nanoseconds.  So I don't think that either one is exactly
what you want.  The only benefit in your case would be that
clock_gettime with CLOCK_REALTIME_COARSE would potentially be faster
since it doesn't need to access any hardware.

-- 
Jeff Ollie


More information about the Cialug mailing list