Setup the default timezone is very necessary for proper data processing sends from various countries. This article will help you to know how can we set up a default timezone in PHP configuration file (php.ini) or inside any php script for temporary use.
Setup Timezone in php.ini
To setup default timezone for your php environment, follow below 4 simple steps.
1. Location of php.ini – Find out your correct php.ini configuration file. Following is some default php.ini locations
2. Choose correct timezone – What timezone you need to configure in your php.ini file. Use below link to find available timezones for php.
3. Update timezone in php.ini – Finally edit your php.ini configuration file and update proper timezone value in date.timezone setting tag. For example, you want to configure ‘America/New_York’ as your default timezone.
date.timezone = "America/New_York "
4. Restart Apache Service – Now just restart Apache service as per setup.
Setup Timezone in PHP Script
You can also set the timezone for a single PHP script by defining timezone inside the PHP script. Simply edit your PHP script and add date_default_timezone_set(“XXX”) line at top of script. Change XXX with your preferred timezone.
1 2 3 | <?php date_default_timezone_set("America/New_York"); ?> |