Re: Sensibly accounting for timezone differences?

From: Date: Mon, 17 Mar 2003 14:12:48 +0000
Subject: Re: Sensibly accounting for timezone differences?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139953@lists.php.net to get a copy of this message
on 17/03/03 11:55 PM, M Wells (autumn@bigpond.net.au) wrote: > I'm an Australian PHP developer and host most of my web sites on US > servers. One in particular is primarily accessed by Australian visitors > and I want to be able to reflect Australian Eastern Standard Times when > writing / reporting records, rather than the server time, which is set > to US Eastern Standard Time. > > I'm wondering if anyone can tell me if there is a sensible way to do > this easily? I'm also an Australian developer, with many many sites hosted in the US. My base library of code includes a config file, which amongst many things, has a setting for a time difference (14 hours). I'm not picky enough to be worried about daylight savings though (given that most of Australia has different start/end dates to begin with). I choose to store all dates in my MySQL database using unix timestamps (seconds since 1970), so, 60 sec x 60 min x 14 hrs = 50400 seconds behind. To get the current time (untested): <? $cfg_time_difference = 50400; $date = date('Y-M-D h:m:s',time() + $cfg_time_difference); echo "the current time in Australia is {$date}"; ?> I tend to insert all dates into MySQl in GMT, then add the time difference to the time after I query the database, so I wrote a small function which formats all my timestamps for me, site wide, as I pull them out of the database, to my chosen format (eg 'Y-M-D h:m:s'), with the adjustment. That's enough typing for today :) Justin

« previous php.general (#139953) next »