Lista amerykańskich stref czasowych dla PHP do użycia? [zamknięte]

zamknięte. to pytanie nie spełnia wytycznych dotyczących przepełnienia stosu . Obecnie nie przyjmuje odpowiedzi.

chcesz poprawić to pytanie? Update the pytanie więc to on-topic {[3] } dla przepełnienia stosu.

Zamknięte 5 lat temu .

Popraw to pytanie

Czy jest tylko lista stref czasowych dla Stanów Zjednoczonych, których mogę używać w php? Im używając nazw stref czasowych z php takich jak Ameryka / Anchorage, php wymienia strefy czasowe tutaj:

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

Chcę wyświetlić je w rozwijanej dla użytkownika, aby wybrać, ale potrzebuję tylko te dla USA, nie chcę pokazać kilka, które są poza USA.

Author: John, 2011-02-14

4 answers

Oto lista, którą znalazłem:

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
 91
Author: John,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-14 06:01:37

Jak powiedział deceze, możesz użyć flagi PER_COUNTRY.

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

Wyjście:

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
 54
Author: jgrowl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-10 20:31:14

Automatycznie otrzymasz listę amerykańskich stref czasowych:

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);'));
}

Zauważ, że będzie to również strefa czasowa Ameryki Południowej, Kanady itp. Możesz pobawić się z DateTimeZone::PER_COUNTRY jako filtrem {[2] } dla PHP 5.3 i zobaczyć, czy to Cię interesuje, czy chcesz, lub przefiltrować pełną listę dla US/. Najlepszym wyborem jest jednak ręczne zaznaczenie stref czasowych.

 5
Author: deceze,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-14 05:55:40

Brute-force sposób, aby uzyskać wszystkie strefy czasowe w danym kraju za pomocą GeoIP PHP. Kod nie ma wyglądać ładnie. Powinieneś zadzwonić tylko raz i gdzieś zapisać wynik.

$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);
 0
Author: maryo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-13 08:50:43