Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Getting a client and server to agree on UTC time [SOLVED]



On 19 December 2010 18:03, Dave M G <dave@example.com> wrote:
> On the PHP side, the key was date_default_timezone_set("UTC"). That
> cleared up some weird results I was getting by just using time() on its own.

Glad you got it sorted out. But just to clarify this in case this, and
the example Darren posted, gives somebody the wrong idea (or to give
some kind person a chance to fix my understanding of this if I'm
wrong):

In PHP, time() always returns a UTC timestamp. It doesn't matter what
you do with date_default_timezone_set().  The default timezone can be
anything you like - time() will always return the same number at any
given instant. This is the point of the example Darren quoted from the
comments to the PHP manual: They set it to a couple of different
things, and proved it returned the same number either way.

What date_default_timezone_set affects is things like date() and
mktime() that deal with converting UTC timestamps into human-readable
dates and back again. Because these functions deal with human-readable
dates and humans like to work with their local time, they also take
account of the timezone. The alternative functions gmdate() and
gmmktime() will give you UTC-based human-readable dates that ignore
the default timezone. (If you find these last two functions helpful,
there's a good chance you're doing something wrong.)

If date_default_timezone_set() helped you here, it was probably
actually fixing something you were doing with date() elsewhere in the
script.

-- 
Edmund Edgar
Founder, KK Social Minds
Educational Technology for the Web and Virtual Worlds

ed@example.com
+81 090 3912 3380
Skype: edmundedgar
Second Life: Edmund Earp
Linked In: edmundedgar
Twitter: @edmundedgar
http://www.socialminds.jp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links