List of Us Time Zones for PHP to Use

List of US Time Zones for PHP to use?

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

PHP Timezone List

Take my array of time zones, which I made specially for select element. It is associated array where key is PHP time zone and value is human representation. This is it:

$timezones = array(
'Pacific/Midway' => "(GMT-11:00) Midway Island",
'US/Samoa' => "(GMT-11:00) Samoa",
'US/Hawaii' => "(GMT-10:00) Hawaii",
'US/Alaska' => "(GMT-09:00) Alaska",
'US/Pacific' => "(GMT-08:00) Pacific Time (US & Canada)",
'America/Tijuana' => "(GMT-08:00) Tijuana",
'US/Arizona' => "(GMT-07:00) Arizona",
'US/Mountain' => "(GMT-07:00) Mountain Time (US & Canada)",
'America/Chihuahua' => "(GMT-07:00) Chihuahua",
'America/Mazatlan' => "(GMT-07:00) Mazatlan",
'America/Mexico_City' => "(GMT-06:00) Mexico City",
'America/Monterrey' => "(GMT-06:00) Monterrey",
'Canada/Saskatchewan' => "(GMT-06:00) Saskatchewan",
'US/Central' => "(GMT-06:00) Central Time (US & Canada)",
'US/Eastern' => "(GMT-05:00) Eastern Time (US & Canada)",
'US/East-Indiana' => "(GMT-05:00) Indiana (East)",
'America/Bogota' => "(GMT-05:00) Bogota",
'America/Lima' => "(GMT-05:00) Lima",
'America/Caracas' => "(GMT-04:30) Caracas",
'Canada/Atlantic' => "(GMT-04:00) Atlantic Time (Canada)",
'America/La_Paz' => "(GMT-04:00) La Paz",
'America/Santiago' => "(GMT-04:00) Santiago",
'Canada/Newfoundland' => "(GMT-03:30) Newfoundland",
'America/Buenos_Aires' => "(GMT-03:00) Buenos Aires",
'Greenland' => "(GMT-03:00) Greenland",
'Atlantic/Stanley' => "(GMT-02:00) Stanley",
'Atlantic/Azores' => "(GMT-01:00) Azores",
'Atlantic/Cape_Verde' => "(GMT-01:00) Cape Verde Is.",
'Africa/Casablanca' => "(GMT) Casablanca",
'Europe/Dublin' => "(GMT) Dublin",
'Europe/Lisbon' => "(GMT) Lisbon",
'Europe/London' => "(GMT) London",
'Africa/Monrovia' => "(GMT) Monrovia",
'Europe/Amsterdam' => "(GMT+01:00) Amsterdam",
'Europe/Belgrade' => "(GMT+01:00) Belgrade",
'Europe/Berlin' => "(GMT+01:00) Berlin",
'Europe/Bratislava' => "(GMT+01:00) Bratislava",
'Europe/Brussels' => "(GMT+01:00) Brussels",
'Europe/Budapest' => "(GMT+01:00) Budapest",
'Europe/Copenhagen' => "(GMT+01:00) Copenhagen",
'Europe/Ljubljana' => "(GMT+01:00) Ljubljana",
'Europe/Madrid' => "(GMT+01:00) Madrid",
'Europe/Paris' => "(GMT+01:00) Paris",
'Europe/Prague' => "(GMT+01:00) Prague",
'Europe/Rome' => "(GMT+01:00) Rome",
'Europe/Sarajevo' => "(GMT+01:00) Sarajevo",
'Europe/Skopje' => "(GMT+01:00) Skopje",
'Europe/Stockholm' => "(GMT+01:00) Stockholm",
'Europe/Vienna' => "(GMT+01:00) Vienna",
'Europe/Warsaw' => "(GMT+01:00) Warsaw",
'Europe/Zagreb' => "(GMT+01:00) Zagreb",
'Europe/Athens' => "(GMT+02:00) Athens",
'Europe/Bucharest' => "(GMT+02:00) Bucharest",
'Africa/Cairo' => "(GMT+02:00) Cairo",
'Africa/Harare' => "(GMT+02:00) Harare",
'Europe/Helsinki' => "(GMT+02:00) Helsinki",
'Europe/Istanbul' => "(GMT+02:00) Istanbul",
'Asia/Jerusalem' => "(GMT+02:00) Jerusalem",
'Europe/Kiev' => "(GMT+02:00) Kyiv",
'Europe/Minsk' => "(GMT+02:00) Minsk",
'Europe/Riga' => "(GMT+02:00) Riga",
'Europe/Sofia' => "(GMT+02:00) Sofia",
'Europe/Tallinn' => "(GMT+02:00) Tallinn",
'Europe/Vilnius' => "(GMT+02:00) Vilnius",
'Asia/Baghdad' => "(GMT+03:00) Baghdad",
'Asia/Kuwait' => "(GMT+03:00) Kuwait",
'Africa/Nairobi' => "(GMT+03:00) Nairobi",
'Asia/Riyadh' => "(GMT+03:00) Riyadh",
'Europe/Moscow' => "(GMT+03:00) Moscow",
'Asia/Tehran' => "(GMT+03:30) Tehran",
'Asia/Baku' => "(GMT+04:00) Baku",
'Europe/Volgograd' => "(GMT+04:00) Volgograd",
'Asia/Muscat' => "(GMT+04:00) Muscat",
'Asia/Tbilisi' => "(GMT+04:00) Tbilisi",
'Asia/Yerevan' => "(GMT+04:00) Yerevan",
'Asia/Kabul' => "(GMT+04:30) Kabul",
'Asia/Karachi' => "(GMT+05:00) Karachi",
'Asia/Tashkent' => "(GMT+05:00) Tashkent",
'Asia/Kolkata' => "(GMT+05:30) Kolkata",
'Asia/Kathmandu' => "(GMT+05:45) Kathmandu",
'Asia/Yekaterinburg' => "(GMT+06:00) Ekaterinburg",
'Asia/Almaty' => "(GMT+06:00) Almaty",
'Asia/Dhaka' => "(GMT+06:00) Dhaka",
'Asia/Novosibirsk' => "(GMT+07:00) Novosibirsk",
'Asia/Bangkok' => "(GMT+07:00) Bangkok",
'Asia/Jakarta' => "(GMT+07:00) Jakarta",
'Asia/Krasnoyarsk' => "(GMT+08:00) Krasnoyarsk",
'Asia/Chongqing' => "(GMT+08:00) Chongqing",
'Asia/Hong_Kong' => "(GMT+08:00) Hong Kong",
'Asia/Kuala_Lumpur' => "(GMT+08:00) Kuala Lumpur",
'Australia/Perth' => "(GMT+08:00) Perth",
'Asia/Singapore' => "(GMT+08:00) Singapore",
'Asia/Taipei' => "(GMT+08:00) Taipei",
'Asia/Ulaanbaatar' => "(GMT+08:00) Ulaan Bataar",
'Asia/Urumqi' => "(GMT+08:00) Urumqi",
'Asia/Irkutsk' => "(GMT+09:00) Irkutsk",
'Asia/Seoul' => "(GMT+09:00) Seoul",
'Asia/Tokyo' => "(GMT+09:00) Tokyo",
'Australia/Adelaide' => "(GMT+09:30) Adelaide",
'Australia/Darwin' => "(GMT+09:30) Darwin",
'Asia/Yakutsk' => "(GMT+10:00) Yakutsk",
'Australia/Brisbane' => "(GMT+10:00) Brisbane",
'Australia/Canberra' => "(GMT+10:00) Canberra",
'Pacific/Guam' => "(GMT+10:00) Guam",
'Australia/Hobart' => "(GMT+10:00) Hobart",
'Australia/Melbourne' => "(GMT+10:00) Melbourne",
'Pacific/Port_Moresby' => "(GMT+10:00) Port Moresby",
'Australia/Sydney' => "(GMT+10:00) Sydney",
'Asia/Vladivostok' => "(GMT+11:00) Vladivostok",
'Asia/Magadan' => "(GMT+12:00) Magadan",
'Pacific/Auckland' => "(GMT+12:00) Auckland",
'Pacific/Fiji' => "(GMT+12:00) Fiji",
);

Generating a drop down list of timezones with PHP

I would do it in PHP, except I would avoid doing preg_match 100 some times and do this to generate your list.

$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);

Also, I would use PHP's names for the 'timezones' and forget about GMT offsets, which will change based on DST.
Code like that in phpbb is only that way b/c they are still supporting PHP4 and can't rely on the DateTime or DateTimeZone objects being there.

Get all timezones

You can use IntlTimeZone::getDisplayName(), e.g.:

echo IntlTimeZone::createTimeZone("Australia/Darwin")->getDisplayName();

Outputs:

Australian Central Standard Time

Though many will change throughout the year for daylight saving. If you want to check for this and add the alternate daylight/summer display name you can do something like:

$tz = IntlTimeZone::createTimeZone("America/Los_Angeles");
echo $tz->getDisplayName(), "\n";
if ($tz->useDaylightTime()) {
echo $tz->getDisplayName(true);
}

which outputs:

Pacific Standard Time
Pacific Daylight Time

What php timezone I use for San Francisco, California, United Stated

I think America/Los_Angeles should work fine.

PHP - Filters List of Timezone as Array

This is my solution. I have an hardcoded array with the timezone identifier and display (for frontend use), which I use to generate an array with the right offset displays.

    static function generateTimeZoneList()
{
static $timezone_list;

if(!isset($timezone_list) || empty($timezone_list))
{
$identifiers = self::getIdentifiers(); //get identifiers list

$temp_list = array();
foreach( $identifiers as $timezone => $display )
{
$tz = new DateTimeZone($timezone);
$temp_list[$timezone] = $tz->getOffset(new DateTime);
}
// sort timezone by offset
asort($temp_list);

foreach($temp_list as $timezone => $offset)
{
$offset_prefix = $offset < 0 ? '-' : '+';
$offset_formatted = gmdate( 'H:i', abs($offset) );

$pretty_offset = "GMT${offset_prefix}${offset_formatted}";

$display = $identifiers[$timezone];
$timezone_list[$timezone] = "($pretty_offset) $display";
}
}
return $timezone_list;
}

/**
* Format: identifier => display name
*/
static function getIdentifiers()
{
static $identifiers = array(
"Africa/Cairo" => " Cairo",
"Africa/Casablanca" => " Casablanca",
"Africa/Harare" => " Harare",
"Africa/Johannesburg" => " Pretoria",
"Africa/Lagos" => " West Central Africa",
"Africa/Monrovia" => " Monrovia",
"Africa/Nairobi" => " Nairobi",
"America/Argentina/Buenos_Aires" => " Buenos Aires",
"America/Argentina/Buenos_Aires" => " Georgetown",
"America/Bogota" => " Quito",
"America/Bogota" => " Bogota",
"America/Caracas" => " Caracas",
"America/Chihuahua" => " La Paz",
"America/Chihuahua" => " Chihuahua",
"America/Godthab" => " Greenland",
"America/La_Paz" => " La Paz",
"America/Lima" => " Lima",
"America/Los_Angeles" => " Pacific Time (US & Canada)",
"America/Managua" => " Central America",
"America/Mazatlan" => " Mazatlan",
"America/Mexico_City" => " Mexico City",
"America/Mexico_City" => " Guadalajara",
"America/Monterrey" => " Monterrey",
"America/Noronha" => " Mid-Atlantic",
"America/Santiago" => " Santiago",
"America/Sao_Paulo" => " Brasilia",
"America/Tijuana" => " Tijuana",
"Asia/Almaty" => " Almaty",
"Asia/Baghdad" => " Baghdad",
"Asia/Baku" => " Baku",
"Asia/Bangkok" => " Hanoi",
"Asia/Bangkok" => " Bangkok",
"Asia/Calcutta" => " Chennai",
"Asia/Calcutta" => " Mumbai",
"Asia/Calcutta" => " New Delhi",
"Asia/Calcutta" => " Sri Jayawardenepura",
"Asia/Chongqing" => " Chongqing",
"Asia/Dhaka" => " Dhaka",
"Asia/Dhaka" => " Astana",
"Asia/Hong_Kong" => " Beijing",
"Asia/Hong_Kong" => " Hong Kong",
"Asia/Irkutsk" => " Irkutsk",
"Asia/Jakarta" => " Jakarta",
"Asia/Jerusalem" => " Jerusalem",
"Asia/Kabul" => " Kabul",
"Asia/Kamchatka" => " Kamchatka",
"Asia/Karachi" => " Karachi",
"Asia/Karachi" => " Islamabad",
"Asia/Katmandu" => " Kathmandu",
"Asia/Kolkata" => " Kolkata",
"Asia/Krasnoyarsk" => " Krasnoyarsk",
"Asia/Kuala_Lumpur" => " Kuala Lumpur",
"Asia/Kuwait" => " Kuwait",
"Asia/Magadan" => " Solomon Is.",
"Asia/Magadan" => " Magadan",
"Asia/Magadan" => " New Caledonia",
"Asia/Muscat" => " Abu Dhabi",
"Asia/Muscat" => " Muscat",
"Asia/Novosibirsk" => " Novosibirsk",
"Asia/Rangoon" => " Rangoon",
"Asia/Riyadh" => " Riyadh",
"Asia/Seoul" => " Seoul",
"Asia/Singapore" => " Singapore",
"Asia/Taipei" => " Taipei",
"Asia/Tashkent" => " Tashkent",
"Asia/Tbilisi" => " Tbilisi",
"Asia/Tehran" => " Tehran",
"Asia/Tokyo" => " Osaka",
"Asia/Tokyo" => " Tokyo",
"Asia/Tokyo" => " Sapporo",
"Asia/Ulan_Bator" => " Ulaan Bataar",
"Asia/Urumqi" => " Urumqi",
"Asia/Vladivostok" => " Vladivostok",
"Asia/Yakutsk" => " Yakutsk",
"Asia/Yekaterinburg" => " Ekaterinburg",
"Asia/Yerevan" => " Yerevan",
"Atlantic/Azores" => " Azores",
"Atlantic/Cape_Verde" => " Cape Verde Is.",
"Australia/Adelaide" => " Adelaide",
"Australia/Brisbane" => " Brisbane",
"Australia/Canberra" => " Canberra",
"Australia/Darwin" => " Darwin",
"Australia/Hobart" => " Hobart",
"Australia/Melbourne" => " Melbourne",
"Australia/Perth" => " Perth",
"Australia/Sydney" => " Sydney",
"Canada/Atlantic" => " Atlantic Time (Canada)",
"Canada/Newfoundland" => " Newfoundland",
"Canada/Saskatchewan" => " Saskatchewan",
"Etc/Greenwich" => " Greenwich Mean Time : Dublin",
"Europe/Amsterdam" => " Amsterdam",
"Europe/Athens" => " Athens",
"Europe/Belgrade" => " Belgrade",
"Europe/Berlin" => " Berlin",
"Europe/Berlin" => " Bern",
"Europe/Bratislava" => " Bratislava",
"Europe/Brussels" => " Brussels",
"Europe/Bucharest" => " Bucharest",
"Europe/Budapest" => " Budapest",
"Europe/Copenhagen" => " Copenhagen",
"Europe/Helsinki" => " Helsinki",
"Europe/Helsinki" => " Kyiv",
"Europe/Istanbul" => " Istanbul",
"Europe/Lisbon" => " Lisbon",
"Europe/Ljubljana" => " Ljubljana",
"Europe/London" => " Edinburgh",
"Europe/London" => " London",
"Europe/Madrid" => " Madrid",
"Europe/Minsk" => " Minsk",
"Europe/Moscow" => " St. Petersburg",
"Europe/Moscow" => " Moscow",
"Europe/Paris" => " Paris",
"Europe/Prague" => " Prague",
"Europe/Riga" => " Riga",
"Europe/Rome" => " Rome",
"Europe/Sarajevo" => " Sarajevo",
"Europe/Skopje" => " Skopje",
"Europe/Sofia" => " Sofia",
"Europe/Stockholm" => " Stockholm",
"Europe/Tallinn" => " Tallinn",
"Europe/Vienna" => " Vienna",
"Europe/Vilnius" => " Vilnius",
"Europe/Volgograd" => " Volgograd",
"Europe/Warsaw" => " Warsaw",
"Europe/Zagreb" => " Zagreb",
"Pacific/Auckland" => " Wellington",
"Pacific/Auckland" => " Auckland",
"Pacific/Fiji" => " Fiji",
"Pacific/Fiji" => " Marshall Is.",
"Pacific/Guam" => " Guam",
"Pacific/Honolulu" => " Hawaii",
"Pacific/Kwajalein" => " International Date Line West",
"Pacific/Midway" => " Midway Island",
"Pacific/Port_Moresby" => " Port Moresby",
"Pacific/Samoa" => " Samoa",
"Pacific/Tongatapu" => " Nuku'alofa",
"US/Alaska" => " Alaska",
"US/Arizona" => " Arizona",
"US/Central" => " Central Time (US & Canada)",
"US/East-Indiana" => " Indiana (East)",
"US/Eastern" => " Eastern Time (US & Canada)",
"US/Mountain" => " Mountain Time (US & Canada)",
"UTC" => " UTC"
);

return $identifiers;
}

The result looks similar to this,

array (size=121)
'Pacific/Midway' => string '(GMT-11:00) Midway Island' (length=26)
'Pacific/Samoa' => string '(GMT-11:00) Samoa' (length=18)
'Pacific/Honolulu' => string '(GMT-10:00) Hawaii' (length=19)
'US/Alaska' => string '(GMT-08:00) Alaska' (length=19)
'America/Los_Angeles' => string '(GMT-07:00) Pacific Time (US & Canada)' (length=39)
'US/Arizona' => string '(GMT-07:00) Arizona' (length=20)
'America/Tijuana' => string '(GMT-07:00) Tijuana' (length=20)
'Canada/Saskatchewan' => string '(GMT-06:00) Saskatchewan' (length=25)
'America/Managua' => string '(GMT-06:00) Central America' (length=28)
'America/Mazatlan' => string '(GMT-06:00) Mazatlan' (length=21)
'America/Chihuahua' => string '(GMT-06:00) Chihuahua' (length=22)
'US/Mountain' => string '(GMT-06:00) Mountain Time (US & Canada)' (length=40)
'America/Lima' => string '(GMT-05:00) Lima' (length=17)

Get the official American time zone in PHP?

You haven't thought this through.

Many US states have multiple time zones. For example, South Dakota has both Mountain and Central time zones.

South Dakota Time Zone Map

If you desire to resolve a location to a time zone, you will need a much more granular location. Ideally, a latitude and longitude. If you don't have one, you can approximate the centroid lat/lon of a zip code, and then use that against any of many various services or databases that will resolve that to a time zone. But be very careful, not all zip codes represent physical locations, and zip codes change frequently.

Time zones with and without DST in PHP

The approach you describe has been done before, and always has the same problems:

  • Most users aren't smart enough to know whether to check the box or not.
  • It doesn't make sense to even have the box, since the time zone rules have all the details of whether or not DST applies, when it applies, and by how much.
  • Time zone abbreviations are ambiguous. For example, without any other information, how do you know that CST means US Central Standard Time? It might mean China Standard Time or Cuba Standard Time. There is a list here that illustrates all of the variations.
  • There isn't always agreement about what the abbreviation should be. For example, is Hawaii in HST or HAST?

It is always best to use the actual IANA time zone identifier, such as America/Phoenix or America/Los_Angeles. If you need an easier way for your users to pick the correct time zone, try a map-based picker, such as this one.

To clarify your concerns about the operating system time zone affecting PHP.

  • If you just say new DateTime(), then yes - it will pick up the default time zone. This can be changed with a call to date_default_timezone_set, but the initial setting comes out of the date.timezone setting in the php.ini file, or from the TZ environment variable of the OS.

  • It's always better to be explicit about the time zone, so you are not affected by any of these defaults.

    For example, to get the current time in Phoenix:

    new DateTime(null, new DateTimeZone('America/Phoenix'))

    To get it in UTC:

    new DateTime(null, new DateTimeZone('UTC'))
  • You can use UTC where it makes sense, but it is not a mandate. Where it matters most is when you save/retrieve from the database, or when transmitting across an api, web service, etc.

  • If you are always explicit, then the time zone of the server doesn't really matter. Linux will sync the system bios to UTC regardless of the time zone. Windows will sync the bios with local time, but has some internals such that you can always get the correct UTC time still. (rather ugly, but works).

  • But still, it is a "best practice" to set servers to UTC time zone. The main reason is so that you find out early that you have time-zone dependent code. (The worst time to find out is in the middle of the night during a DST transition you didn't plan for.)

Timezone list with abbreviation, name, and gmt php

The example list you've shown looks like it was derived from the data provided by the U.S. Naval Observatory's Time Service Dept.. They have since updated names like "USSR Zone 3" to be called "Russian Federation zone three". But these are just some administrator's own personal interpretations of what they think time zones should be named. They aren't official by any means.

If you search the web, you'll find plenty of other static web sites (like here and here) that seem to think these are somehow official and set in stone. That's just not the case. I mean, if you live in Russia do you think you would ever really say that you follow "Time Zone 3"? No, you would probably say that you follow "Moscow Time", or perhaps "Moscow Standard Time". (See Wikipedia's entry on Time in Russia.)

So that's just one example, but the question then of where to get the time zone names from? The general problem is that they are not in the TZDB data, so PHP doesn't give them back to you. As I've illustrated, they are subject to interpretation. Time zone abbreviations are also subject to interpretation. If you want a slightly better interpretation, the one provided by here appears to be more plausible. But it will probably still need to be filtered for your purposes.

A better source of time zone names comes from the Unicode CLDR. They offer a very large data set that translates many things into different languages, and one of the things they cover are the names of the time zones. But to get a time zone name from an IANA time zone key out of the CLDR data, you have to jump through a lot of hoops:

  • Look up the key in the CLDR MetaZones list.

    CLDR Metazone Mapping Data

  • Find the Language File that you are interested in, English for example.

  • Find the metazone in the language file, and determine which form of that name you want.

    CLDR Translation Data

Of course, you would have to do all of that programmatically from their XML or JSON data sources. And you'd have to do it for each time zone you were interested in.

Why go to all that trouble? Well if you have a user who speaks another language, for example French, then would you want to show them "Central European Standard Time" or "heure normale de l’Europe centrale"? Only the CLDR can give you that sort of translation.

So I know this didn't directly give you PHP code that you can use right away, but hopefully now you understand why this isn't directly possible, and that just about any list you come upon is subject to someone's own personal interpretation and is likely to be outdated or partially incorrect.



Related Topics



Leave a reply



Submit