PHP Timezone List

PHP Timezone List

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Building a PHP Timezone Dropdown: Handling Offsets and Display Names

Generating a timezone list for a <select> element is a common requirement in web applications, but it often trips developers up when dealing with offset calculations. The core issue usually stems from how the DateTimeZone class reports its time offset versus the actual local time displayed by the system.

When you use DateTime::createFromFormat or construct a DateTime object without specifying a timezone, PHP defaults to the server's environment settings (e.g., UTC or the system default). If your server is running in UTC, a DateTime object created with new DateTime(null) will reflect UTC time. Consequently, when you calculate the offset using $zone->getOffset($c), you are comparing the local zone's representation against UTC.

Consider the case of Asia/Singapore. Singapore operates on UTC+8. However, if your code logic relies on a DateTime object initialized in UTC, and you attempt to format the display time based on that UTC reference while calculating the offset, discrepancies arise if the server environment isn't strictly UTC or if the calculation logic assumes a different baseline. The source material highlights a specific scenario where a developer observes an incorrect GMT offset (reading +9 instead of +8) for Singapore. This typically indicates that the $c object used in getOffset() is not aligned with the expected UTC baseline, or the server's default timezone setting is interfering with the calculation logic.

To ensure accuracy, you must explicitly create your reference time in UTC before calculating offsets. The following pattern guarantees a consistent baseline regardless of the server's default configuration:

// Always use 'UTC' as the date string to force a UTC-based object
$c = new DateTime('now', new DateTimeZone('UTC')); 
$offset = $tz->getOffset($c);

By forcing the DateTime object into the UTC timezone, you eliminate ambiguity. The getOffset() method will then return seconds relative to UTC that are mathematically correct for every region, from America/New_York to Asia/Hong_Kong.

Beyond fixing the offset logic, there is the matter of display names. Developers often want a friendly string like "UTC+8 Asia/Singapore" rather than just the raw identifier. While DateTimeZone::listIdentifiers() provides the ID, it does not provide a human-readable name directly. You generally need to rely on the system's underlying timezone database (like IANA).

To construct a display-friendly list, you can iterate through the identifiers and format them using a helper function that combines the offset sign, hours, minutes, and the identifier itself. Here is a robust approach that sorts the data by offset and formats it cleanly:

$data = [];
$added = [];

// Iterate through all available zones
foreach (DateTimeZone::listIdentifiers() as $tzId) {
    $zone = new DateTimeZone($tzId);
    
    // Create a UTC-based reference date to get accurate offset
    $c = new DateTime('now', new DateTimeZone('UTC'));
    $offsetSeconds = $zone->getOffset($c);
    
    // Calculate human-readable offset (e.g., +05:30)
    $hours = abs(floor($offsetSeconds / 3600));
    $minutes = abs(floor(($offsetSeconds % 3600) / 60));
    $sign = ($offsetSeconds > 0) ? '+' : '-';
    $offsetStr = sprintf('%s%02d:%02d', $sign, $hours, $minutes);
    
    // Get the display name if available in the database, otherwise fall back to ID
    $displayName = $zone->getName();

    $data[] = [
        'id' => $tzId,
        'name' => $displayName,
        'offset' => $offsetStr
    ];
}

// Sort by offset (ascending)
usort($data, function($a, $b) {
    return $a['offset'] <=> $b['offset'];
});

// Build the options array for the <select> element
$options = [];
foreach ($data as $item) {
    // Format: UTC+8 Asia/Singapore
    $options[$item['id']] = $item['offset'] . ' ' . $item['name'];
}

This approach avoids hardcoding regions or relying on potentially incomplete abbreviation lists. It leverages the full list of identifiers, calculates offsets dynamically against a strict UTC baseline, and extracts the native name provided by the system's timezone database. This ensures that even for complex zones like America/New_York, which shifts between EST and EDT, the displayed offset will reflect the current time of year accurately.

If you are using Laravel, you might consider leveraging existing packages or helper functions to generate these lists, but understanding the underlying DateTimeZone mechanics remains essential for troubleshooting edge cases where default offsets appear incorrect.

Our network