HOWTO · PHP
New York Timezone in PHP
Set the America/New_York timezone in PHP and format a New York date or time with date().
On this page
To display a date or time in New York, set PHP’s timezone to America/New_York before calling date(). The identifier is America/New_York; New_York by itself is not the full PHP timezone identifier.
New York Timezone in PHP
PHP’s supported timezone identifiers are listed in the manual. Set the default timezone with date_default_timezone_set(), then use date_default_timezone_get() to inspect the configured identifier. The setter returns true when it accepts the timezone and false when it does not. Check that result if the identifier comes from configuration or user input, and handle a false result before formatting a date.
This complete example sets New York time, confirms the configured timezone, and formats the local date and time:
<?php
$configured = date_default_timezone_set('America/New_York');
if ($configured) {
echo 'Timezone: ' . date_default_timezone_get() . PHP_EOL;
echo 'Date: ' . date('Y-m-d') . PHP_EOL;
echo 'Time: ' . date('H:i:s') . PHP_EOL;
}
The example prints the configured identifier, followed by the date and time when you run it. Those last two values depend on the execution time. The format string controls which parts of the local date and time appear. In Y-m-d, Y is a four-digit year, m is a two-digit month, and d is a two-digit day of the month. H:i:s uses a 24-hour hour, minutes, and seconds; use h:i:sa for a 12-hour hour with an am or pm suffix. Each call to date() uses the default timezone set earlier, so the date can differ from the server’s local date near midnight.
For example, these format strings produce common date layouts: Y/m/d, d/m/Y, Y.m.d, and d-m-Y. The l format character spells out the weekday, while lowercase h and uppercase H select 12-hour and 24-hour time respectively. Choose a format that suits the display context, and keep in mind that date() formats the current time unless you pass it a timestamp as its second argument.
The timezone setting applies to the current PHP execution context and changes the default used by date and time functions that rely on it. If the application already manages timezone settings, set the timezone at the appropriate request or application boundary so unrelated code does not depend on an unexpected default. Use the same identifier spelling, America/New_York, when setting and checking the timezone.
For a particular moment rather than the current time, pass a Unix timestamp as the second argument to date(). For example, date('Y-m-d H:i:s', $timestamp) formats that moment using the configured timezone. A timestamp represents an instant; the timezone determines its local clock and calendar display. This distinction is useful when storing event times in a database and showing them to readers in New York.
New York observes seasonal clock changes, so its UTC offset is not constant throughout the year. Using the IANA identifier America/New_York lets PHP apply the relevant timezone rules for the date being formatted. Avoid replacing it with a fixed offset such as -05:00 when the application needs local New York time across the year.
If a project configures timezones centrally, keep that policy in one appropriate place and make date formatting follow it consistently.