[thelist] Why use UTC time?

shawn allen shawn at alterior.net
Mon Feb 24 13:47:02 CST 2003


quoth Erik Mattheis:
> What's the advantage for having unix epoch times always in GMT if your
> app is hosted in a single time zone? Seems useless to me. Nay,
> detrimental.

The UNIX epoch /is/ midnight GMT. Storing time vales relative to
differing timezones on individual files or machines would kinda defeat
the purpose of having a standard, wouldn't it?

> Can anyone point me (or give me) instructions to change this behavior
> on Jaguar/PHP 4.3/MySQL ... so unix time stamps are calculated in
> local time? I've looked in the INI files and couldn't find anything
> and I have failed on google. TIA.

In UNIX, though time is always stored relative to the epoch, all
date-sensitive functions return values relative to the machine's current
timezone (which is just an offset in seconds), unless otherwise
specified. This is a handy convention because it allows you to change
the time zone within any atomic, temporary process without modifying the
timestamps of any permanent objects. In PHP (and many other
environments, including RDBMS's), the TZ environment variable determines
the output of time(), mktime(), date(), etc. To change your timezone,
simply change the environment variable:

putenv('TZ=US/Pacific');

Valid values for TZ are paths for files in your zoneinfo directory -- in
OS X and other BSD's, it's /usr/share/zoneinfo
(/usr/share/zoneinfo/US/Pacific is actually a regular file containing
time zone information).

If values are coming out of PHP as GMT, you might not have properly
configured the time zone on your machine. If you want to change the
timezone for a particular application, you could use apache's mod_env to
set TZ within a VirtualHost block:

<VirtualHost 127.0.0.1>
	ServerName foo
	SetEnv TZ US/Pacific
</VirtualHost>

...or just do it in the PHP. :)

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list