Setting the correct time zone in PHP is crucial for accurate data management and handling time-sensitive operations. In this article, we will explore how to set the time zone to New York using PHP.
How to Set the Time Zone in PHP
To set the time zone to New York in PHP, you need to use the date_default_timezone_set() function and
pass the appropriate time zone identifier as a parameter.
Here’s an example of how to set the time zone to New York in PHP:
date_default_timezone_set("America/New_York");

Credit: www.expedia.com
Showing Local Time in New York
If you want to display the current local time in New York, you can use the date() function along with
the date_default_timezone_set() function.
Here’s an example code snippet:
date_default_timezone_set("America/New_York");
$current_time = date("Y-m-d H:i:s");
echo "Current time in New York: " . $current_time;
Changing PHP Time Zone in php.ini
To change the PHP time zone globally across your website, you can modify the php.ini file. Here’s the step-by-step process:
- Open your cPanel account and navigate to the File Manager.
- Go to the root folder of your website (public_html by default).
- Find the php.ini file and open it.
- Look for the [Date] section.
- Insert the following line:
date.timezone = "America/New_York" - Save the changes and restart your web server (if necessary).

Credit: en.wikipedia.org
PHP Default Time Zone
By default, PHP uses the Coordinated Universal Time (UTC) as the default time zone. To ensure accurate data management and operations, it is essential to configure the PHP time zone correctly.
List of Supported Time Zones
PHP provides a wide range of time zones that you can use in your applications. Here’s a list of some supported time zones:
| Africa | America | Antarctica |
|---|---|---|
| Asia | Atlantic | Australia |
| Europe | Indian | Pacific |
DateTime and DateTimeZone Classes
In PHP, the DateTime and DateTimeZone classes can be used to convert time between different time zones.
Here’s an example: