Chesso Posted May 16, 2007 Share Posted May 16, 2007 Something I never found an answer for a long time ago. It's all fine locally but on web host they are in different location so it's all setup for them on the web server. How can I have the time() and date() functions etc return in my timezone? I'm in AU, Sydney (GMT+10) Quote Link to comment https://forums.phpfreaks.com/topic/51638-solved-time-and-date/ Share on other sites More sharing options...
taith Posted May 16, 2007 Share Posted May 16, 2007 <?php function set_timezone($timezone="0"){ switch($timezone){ case "-12": date_default_timezone_set('Etc/GMT+12'); break; case "-11": date_default_timezone_set('Etc/GMT+11'); break; case "-10": date_default_timezone_set('Etc/GMT+10'); break; case "-9": date_default_timezone_set('Etc/GMT+9'); break; case "-8": date_default_timezone_set('Etc/GMT+8'); break; case "-7": date_default_timezone_set('Etc/GMT+7'); break; case "-6": date_default_timezone_set('Etc/GMT+6'); break; case "-6": date_default_timezone_set('Etc/GMT+5'); break; case "-4": date_default_timezone_set('Etc/GMT+4'); break; case "-3": date_default_timezone_set('Etc/GMT+3'); break; case "-2": date_default_timezone_set('Etc/GMT+2'); break; case "-1": date_default_timezone_set('Etc/GMT+1'); break; case "0": date_default_timezone_set('GMT'); break; case "1": date_default_timezone_set('Etc/GMT-1'); break; case "2": date_default_timezone_set('Etc/GMT-2'); break; case "3": date_default_timezone_set('Etc/GMT-3'); break; case "4": date_default_timezone_set('Etc/GMT-4'); break; case "5": date_default_timezone_set('Etc/GMT-5'); break; case "6": date_default_timezone_set('Etc/GMT-6'); break; case "7": date_default_timezone_set('Etc/GMT-7'); break; case "8": date_default_timezone_set('Etc/GMT-8'); break; case "9": date_default_timezone_set('Etc/GMT-9'); break; case "10": date_default_timezone_set('Etc/GMT-10'); break; case "11": date_default_timezone_set('Etc/GMT-11'); break; case "12": date_default_timezone_set('Etc/GMT-12'); break; } } set_timezone('+10'); ?> and voila! your server thinks its in sydney! lol Quote Link to comment https://forums.phpfreaks.com/topic/51638-solved-time-and-date/#findComment-254370 Share on other sites More sharing options...
Chesso Posted May 16, 2007 Author Share Posted May 16, 2007 So i'm looking for: date_default_timezone_set('Etc/GMT-10'); Is there anywhere special, like just before I use time/date or perhaps just call it the once at the top of pages that make use of time and date? Woah, I didn't realise you could use case statements in PHP lol dang, I could have been using these....... Quote Link to comment https://forums.phpfreaks.com/topic/51638-solved-time-and-date/#findComment-254371 Share on other sites More sharing options...
taith Posted May 16, 2007 Share Posted May 16, 2007 yup! switch() is a great function! just put that tag at the very top of your page... before everything(save session_start()) Quote Link to comment https://forums.phpfreaks.com/topic/51638-solved-time-and-date/#findComment-254372 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.