Jump to content

handling timezones in web applications


bcamp1973

Recommended Posts

hmm...okay, so this is the first time i've had to really think about this.  i'm building an application and i need to give users the ability to set their profile for their current timezone. is there a really clean and simple way to handle this?  also, where might i find a good comprehensive timezone list? :)

Link to comment
https://forums.phpfreaks.com/topic/45781-handling-timezones-in-web-applications/
Share on other sites

if your website is on GMT this would be alot easyer...

check http://nl2.php.net/date for your time and date functions

 

its simply a matter of minusing or ading an extra hour to GMT

like

if(perosntimezone==gmt+1)

$hour = date(H) + 1;

 

now theres gonna be the triky bit,

its when your servers on the 23 hour.. if you add 1 then it becomes 24:00 not 00:00

so if($hour>23){

$hour=00;

Thanks! Here's my solution...i just pass the date in the 12 hour format, pass the GMT offset (-7 in my case) and TRUE/FALSE for daylight savings...

 

function mydate($date,$offset,$dst=TRUE){

$date=explode(' ',$date);

list($year,$month,$day)=explode('-',$date[0]);
list($hour,$minute,$second)=explode(':',$date[1]);

if(($hour+$offset)>0){
	$hour=$hour+$offset;
} else {
	$hour=($hour+$offset)*-1;
	$day--;
}

if($dst) $hour=$hour+date('I');

return $year.'-'.$month.'-'.str_pad($day,2,'0',STR_PAD_LEFT).' '.str_pad($hour,2,'0',STR_PAD_LEFT).':'.$minute.':'.$second;
}

 

I'm sure it could be more elegant, but it seems to be working :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.