Set your own timezone on a shared hosting
December 6, 2009 § 7 Comments
If you are a web application developer and had opportunities to work on various client servers around the globe, you may have already experienced the timezone related problems in the server script. This problem comes when the hosting is a shared one and the website runs for a different timezone than the server’s timezone. For example – I am running a website for my local community here in Dhaka/Bangladesh (timezone GMT + 7.00) but my server which is a shared one resides in the United States (say a timezone like GMT – 7). As this is a shared server, the timezone was set by the administrator to their local time. So every call to PHP date() and/or time() function will always return the server’s local time causing a mismatch with my local time in my website.
To overcome this situation, you have to change your default date time using PHP function date_default_timezone_set(your_time_zone_string). For my case, it was following:
Add this line before executing/calling any date and/or time functions.
Below might be a quick test for you:
echo 'OLD Time: ' . date('Y-m-d H:i:s a');
echo '<br />';
echo 'New Time: ' . date('Y-m-d H:i:s a');
Read more on function date_default_timezone_set: http://us3.php.net/date_default_timezone_set
See the list of supported timezones here: http://us3.php.net/manual/en/timezones.php