Alex Rivera | Logout

Is time_t returned by time() zone specific?

Asked 2011-09-15T06:13:14.300
9

I am just new to <time.h> and have a question regarding to time_t and time().

I read the function time() documented as follows:

time_t time ( time_t * timer ); Get current time

Get the current calendar time as a time_t object.

The function returns this value, and if the argument is not a null pointer, the value is also set to the object pointed by timer.

The documentation does not talk about time zone.

Thus, for the following C++ code:

time_t t = time(NULL);

If two machines, one in US and the other one in UK, both execute the function call time(NULL) at the same time, will the returned time_t objects be identical?

Will time() returns a value regardless of time zone?

Edit
Report

1 Answer

11

No it's not zone specific. It returns a value that's a count of the number of seconds since 1 Jan 1970 in UTC, ignoring leap seconds. So (in principle) if two machines execute the call at the exact same time, the value returned will be the same, even if they work in two separate time zones.

answered 2011-09-15T06:16:13.747

Your Answer