Re: gettimeofday() seems to return local time
Re: gettimeofday() seems to return local time
- Subject: Re: gettimeofday() seems to return local time
- From: Ragnar Sundblad <email@hidden>
- Date: Tue, 07 Dec 2004 03:26:32 +0100
--On Wed, 1 Dec 2004 17:57:32 -0500 "Michael Rubinstein"
<email@hidden> wrote:
I'm using gettimeofday(), on OS X 10.3.6, to get the time resolution I
need (milliseconds).
If I'm reading the documentation right, I should be getting time in
UTC. However, I'm getting local time.
Should gettimeofday() return local time?
This is not what you asked, put just for the correctness of
the discussion;
Actually, my MacOS X man page says "Greenwich time" and not UTC,
and this is in some senses more correct than the latter.
I think the man pages for gettimeofday() on the OSes that mention
UTC are wrong, as I doubt they will ever return UTC.
UTC is a time scale with all seconds equally long. That means
it has to be corrected for the variations in the movement of
the Earth to keep in sync with the Earth's day and year by
inserting or removing leap seconds every now and then. These
are inserted just before midnight on June 30 or Dec 31.
Since the introduction in 1972, UTC has gotten an extra 22
seconds inserted. In other words, the time 23h 59m 60s has
existed 22 times in this time scale. I doubt any implementation
of gettimeofday() ever returns time stamps that relates to
this time scale (except maybe during the first half of 1972,
depending on how you choose to look at it), since it would make
all programs' conversion routines have to be updated with when
the leap seconds happened, and those have happened every 1.5
year or so.
On the other hand, the clock may be synchronized using NTP that
actually uses the same second ticks as UTC (except when there
are leap seconds which NTP doesn't support so it takes a little
while before everything synchs together again), so in the sense
gettimeofday kind of returns UTC *ticks*.
But gettimeofday still does not return UTC seconds since 1970,
rather GMT seconds (or UT, or UT1, or whatever scale you prefer).
So - get better timing by don't confusing the time scales! :-)
/ragge
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden