bcamp1973 Posted April 5, 2007 Share Posted April 5, 2007 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? Quote Link to comment Share on other sites More sharing options...
only one Posted April 5, 2007 Share Posted April 5, 2007 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; Quote Link to comment Share on other sites More sharing options...
bcamp1973 Posted April 5, 2007 Author Share Posted April 5, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.