47

Is there just a list of time zones for the united states I can use with php? Im using the timezone names from php such as America/Anchorage, php lists time zones here:

http://us.php.net/manual/en/timezones.others.php

I want to display them in a drop down for the user to select but I only need the ones for the US, I dont want to show a bunch that are outside the US.

John
  • 9,840
  • 26
  • 91
  • 137
  • 5
    http://www.php.net/manual/en/timezones.america.php – Shakti Singh Feb 14 '11 at 05:51
  • 1
    @Shakti Singh Thank you, but that is for all of America. Just want the ones for United States. – John Feb 14 '11 at 05:53
  • Is there a reason you can't hand pick them yourself from the list? – David Kuridža Feb 14 '11 at 06:43
  • @David Kuridza Was just looking for something a little more automated. But no worries, looks like I found what I was looking for, thanks! – John Feb 14 '11 at 07:27
  • 4
    **+1 to open**, while technically a list it is directly programming related. There are too many people with reputation on Stack and in RL that don't deserve the powers granted to them. – John Jan 03 '17 at 08:48
  • Go to the final 2 examples in my answer in https://stackoverflow.com/a/68690406/4188092 to get a list of timezones filtered by country code using the php intl module. – Patanjali Aug 07 '21 at 22:47

4 Answers4

110

Here is a list I found:

Eastern Time    America/New_York
Central Time    America/Chicago
Mountain Time   America/Denver
Mountain Time (no DST) America/Phoenix
Pacific Time    America/Los_Angeles
Alaska Time America/Anchorage
Hawaii-Aleutian America/Adak
Hawaii-Aleutian Time (no DST) Pacific/Honolulu
John
  • 9,840
  • 26
  • 91
  • 137
  • 11
    Where did you get this list from? – Jacob Mar 23 '11 at 04:59
  • 4
    It is the list that is distilled from here: http://php.net/manual/en/timezones.america.php – Camden S. Nov 17 '14 at 19:56
  • 1
    The doc referenced by @CamdenS. does indeed contain a list of PHP time zones for "America". But I would still like to see official documentation that these few are all the time zones for the US. Also that doc does not say which time zone each correlates to as provided in this answer (Easter Time, Central, Etc). I suppose one could look up all the US time zones and make sure none are missing from this list (from the left). Then you could look up the places (on the right) and see if they match the time zone (on the left). Is this list really accurate? – still_dreaming_1 Dec 09 '14 at 19:27
  • This link shows all timezones: http://php.net/manual/en/timezones.php – kevnk May 13 '16 at 13:55
  • 1
    This is the go-to list for the American developer, beyond this see here http://php.net/manual/en/timezones.php – drooh Jul 30 '16 at 03:13
  • Don't forget Puerto Rico: America/Puerto_Rico – Ruben Estrada Mar 17 '22 at 18:40
57

As deceze said, you can use the PER_COUNTRY flag.

$timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US');
foreach($timezone_identifiers as $timezone_identifier) {
  echo "$timezone_identifier\n";
}

Output:

America/Adak
America/Anchorage
America/Boise
America/Chicago
America/Denver
America/Detroit
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Los_Angeles
America/Menominee
America/Metlakatla
America/New_York
America/Nome
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Phoenix
America/Shiprock
America/Sitka
America/Yakutat
Pacific/Honolulu
jgrowl
  • 2,117
  • 2
  • 17
  • 23
  • 2
    I believe this answer is the one that best answers the OP's request (in his comment) for something automated. It is a complete list and more future-proof. – Michael Greisman Jun 30 '14 at 19:45
7

This will automatically get you a list of American timezones:

if (defined('DateTimeZone::AMERICA')) {
    // PHP 5.3+
    $timezoneIdentifiers = timezone_identifiers_list(DateTimeZone::AMERICA);
} else {
    // PHP 5.2
    $timezoneIdentifiers = timezone_identifiers_list();
    $timezoneIdentifiers = array_filter($timezoneIdentifiers, create_function('$tz', 'return preg_match("/^America\//", $tz);'));
}

Note that this will include South American, Canadian etc timezones as well though. You could play around with DateTimeZone::PER_COUNTRY as a filter to timezone_identifiers_list for PHP 5.3 and see if that gets you want you want, or filter the complete list for US/. The best choice is probably to handpick the timezones though.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

Brute-force way to get ALL timezones per country using PHP's GEOIP. The code is not intended to look nice. You should call this only once and store the result somewhere.

$timezones = array();

foreach (range('A', 'Z') as $i) {
    foreach (range('A', 'Z') as $j) {
        $country = $i . $j;

        foreach (range('A', 'Z') as $k) {
            foreach (range('A', 'Z') as $l) {
                $region = $k . $l;

                if ($timezone = geoip_time_zone_by_country_and_region($country, $region)) {
                    $timezones[$country][$timezone] = true;
                }
            }
        }

        foreach (range(0, 99) as $m) {
            if ($timezone = geoip_time_zone_by_country_and_region($country, sprintf('%02d', $m))) {
                $timezones[$country][$timezone] = true;
            }
        }
    }
}

var_dump($timezones);
maryo
  • 6,679
  • 3
  • 16
  • 9