How to change the date.timezone value in PHP?

If your PHP scripts do not show the correct time, the reason is that most probably your hosting server is in a different timezone. This can be easily done by changing a setting using PHP called date.timezone.

Depending on your location you can set a specific date.timezone value in PHP using the option below which should be added to your local php.ini file :-

date.timezone = “Pacific/Auckland

The example given above assumes you’d like to set the timezone for your PHP scripts to Pacific/Auckland. The full list of supported time zones is available here and you should simply replace Pacific/Auckland with the desired timezone.

Example Script :-

<?php
ini_set(‘date.timezone’, ‘Pacific/Auckland’);
phpinfo();
echo $today = date(“D M j G:i:s T Y”);
?>

Output :-

Before :-

After :-

Current time after changing the value of default time zone

Advertisements

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s