Is clock_gettime UTC or local time zone?

Does the clock_gettime function clock_gettime timestamp measured from an era in UTC or in the local time zone?

I know that time assumed since the UTC era, but I cannot find the link saying that this is true for clock_gettime .

+8
linux posix
source share
3 answers

To quote Wikipedia, Unix Epoch is defined as

time 00:00:00 UTC January 1, 1970 (or 1970-01-01T00: 00: 00Z ISO 8601).

It follows that any reference to the "Epoch" implies UTC.

+13
source share

Actually, the question does not make much sense. See time (7) for an overview of time related functions.

Any watch device returns the time counted from any incident event in the past. The Unix (and Posix) convention should measure it from Epoch (early 1970, as an aix answer ).

Displaying some time in UTC or local time or using the French revolutionary calendar or using the Mayan calendar or any other calendar from any culture you are interested in does not change this time. Only the displayed (or shown form) of that time is displayed.

This is a bit like the two, deux, 1 + 1, or 2, or 10b - with b, meaning binary, are all representations of the same number.

Returning to the question, the clock_gettime man page gives an exact answer to the question. It depends on the requested clk_id , and for CLOCK_REALTIME time has been measured since the Unix era. For other watches (e.g. CLOCK_MONOTONIC ), the start used is not indicated.

(Unfortunately, I am surprised at the number of questions that can be answered very quickly by looking at a person. I don’t understand the logic of people who take more time to ask a question here: by typing man clock_gettime on my Linux server - to the manual pages).

The concept of time zone is only relevant for struct tm returned by localtime and gmtime (and related) functions. Time (for example, some time_t ) measured from an era (for example, the result is time (2) , gettimeofday , clock_gettime with CLOCK_REALTIME ) does not have a time zone .

Unix Age - January 01, 1970 0:00 UTC (by definition (time_t)0 ). In my time zone (MET = Paris / France) is the same era - Thu Jan 1 01:00:00 MET 1970.

+6
source share

it depends.

if you call clock_gettime(1) , most likely the era is the time your Linux started.

0
source share

All Articles