Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Set the Timezone in the php.ini File or PHP Script

When you try to show current date-time or time in your PHP Scripts and get the incorrect value it means your hosting server has a different Timezone.

Setting the right default timezone is very important if you want to work with the date and the time of your web application.

In this tutorial, you will learn how to setup default timezone in the php.ini file or PHP script.

Set the PHP Timezone in PHP Script

You can easily set timezone in your PHP script. You just need to add the date_default_timezone_set(“your time zone”) function in your web application config file.

Adding it to the config file will set it for all PHP files.


Replace ‘Asia/Calcutta’ with your timezone.

If you don’t know your timezone, then check this out.

Set the PHP Timezone in the php.ini File

Set the PHP Timezone in the php.ini File:

Login to cPanel

Open your php.ini file with the File Manager

Add the following line of code to top of your php.ini file: date.timezone = “Asia/Calcutta”

Replace Asia/Calcutta with the timezone from here that corresponds to the time you want.

Click Save Changes button to save the file.

Now access phpinfo page to see the changes.

So, in this tutorial, you have learned how to change timezone in PHP. If you have any query related to this tutorial, feel free to comment.

The post How to Set the Timezone in the php.ini File or PHP Script appeared first on PhpCluster.

This post first appeared on Best PHP Programming Blog, Blog For PHP Developers, PHP Tutorial,PHP Blog For Beginners, please read the originial post: here

Share the post

How to Set the Timezone in the php.ini File or PHP Script


Subscribe to Best Php Programming Blog, Blog For Php Developers, Php Tutorial,php Blog For Beginners

Get updates delivered right to your inbox!

Thank you for your subscription