Why does the time zone matter?
PHP is a language many websites use. It has its own clock setting called a time zone. If the zone is wrong, your posts, orders and emails may show the wrong time. A time zone is a region of the world that shares the same clock time, like "Asia/Kolkata" or "America/New_York".
Method 1: Select PHP Version in cPanel
cPanel is the control panel on most shared and reseller hosting. Menu names can differ a little between versions.
- Log in to cPanel.
- In the Software section, click Select PHP Version.
- Click the Options tab. On some servers, the same page is called MultiPHP INI Editor in the Software section.
- Look for the
date.timezonesetting. Type your time zone in the box, for exampleAsia/Kolkata. - Click Apply or Save.
Method 2: Use a php.ini file
A php.ini file holds PHP settings for your folder.
- Open File Manager in cPanel and go to
public_html. - If a
php.inifile does not exist, click + File and create it. Otherwise, right-click it and choose Edit. - Add this line:
date.timezone = "Asia/Kolkata"
This tells PHP to use that time zone. Replace it with your own zone.
- Save the file.
Method 3: Set it in your code
You can also add this line at the top of a PHP file:
<?php date_default_timezone_set('Asia/Kolkata'); ?>
This sets the zone for that script only.
Check your change
- Create a file called
time.phpwith this inside:
<?php echo date('Y-m-d H:i:s T'); ?>
- Open it in a browser and check the time. Delete the file afterwards.
Tip: Look up the exact zone name on a "list of PHP time zones" page. Spell it exactly, with capital letters. Some apps, such as WordPress, also have their own time zone setting in their admin area.
Quick recap
- The PHP time zone controls the dates and times your site shows.
- Set
date.timezonein Select PHP Version or inphp.ini. - Or use
date_default_timezone_setin code. - Test with a small script.