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
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;

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.