GMT抵消PHP时区

时间:2012-12-07 12:48:57

标签: php timezone gmt

是否可能有类似的东西?

$offset    = -05:00; 
$timezone  = getTimeZone($offset); //return America/New_York 
date_default_timezone_set($timezone);

如果是的话,DST(节日灯)怎么样?

修改

我试过的是

function php_date_default_timezone_set($GMT,$timestamp) { 
              $timezones = array( 
                  '-12:00'=>'Pacific/Kwajalein', 
                  '-11:00'=>'Pacific/Samoa', 
                  '-10:00'=>'Pacific/Honolulu', 
                  '-09:00'=>'America/Juneau', 
                  '-08:00'=>'America/Los_Angeles', 
                  '-07:00'=>'America/Denver', 
                  '-06:00'=>'America/Mexico_City', 
                  '-05:00'=>'America/New_York', 
                  '-04:00'=>'America/Caracas', 
                  '-03:30'=>'America/St_Johns', 
                  '-03:00'=>'America/Argentina/Buenos_Aires', 
                  '-02:00'=>'Atlantic/Azores',
                  '-01:00'=>'Atlantic/Azores', 
                  '+00:00'=>'Europe/London', 
                  '+01:00'=>'Europe/Paris', 
                  '+02:00'=>'Europe/Helsinki', 
                  '+03:00'=>'Europe/Moscow', 
                  '+03:30'=>'Asia/Tehran', 
                  '+04:00'=>'Asia/Baku', 
                  '+04:30'=>'Asia/Kabul', 
                  '+05:00'=>'Asia/Karachi', 
                  '+05:30'=>'Asia/Calcutta', 
                  '+06:00'=>'Asia/Colombo', 
                  '+07:00'=>'Asia/Bangkok', 
                  '+08:00'=>'Asia/Singapore', 
                  '+09:00'=>'Asia/Tokyo', 
                  '+09:00'=>'Australia/Darwin', 
                  '+10:00'=>'Pacific/Guam', 
                  '+11:00'=>'Asia/Magadan', 
                  '+12:00'=>'Asia/Kamchatka' 
              ); 

    date_default_timezone_set($timezones[$GMT]);

    return  date_default_timezone_get();
}  

    echo php_date_default_timezone_set('-05:00',time()); 
   // returns America/New_York

但我不知道这种方式是否正确?

2 个答案:

答案 0 :(得分:4)

不,因为没有这种反向关联。目前有许多时区偏移-05:00。这就是为什么你应该使用时区标识符来识别时区而不是偏移。

答案 1 :(得分:1)

请原谅我带回一个旧问题,但是我使用Offset遇到了同样的问题,而是决定使用这个列表。 (来自Google日历)

不存储偏移量,而是存储实际名称" America / Phoenix"

当用户选择时区时,这就是我现在所拥有的。它完美的主要时区阵容,以及PHP准备就绪。 http://php.net/manual/en/timezones.php

timezones

<select name="timezones">
<option value="Pacific/Midway">(GMT-11:00) Midway</option>
<option value="Pacific/Niue">(GMT-11:00) Niue</option>
<option value="Pacific/Pago_Pago">(GMT-11:00) Pago Pago</option>
<option value="Pacific/Honolulu">(GMT-10:00) Hawaii Time</option>
<option value="Pacific/Rarotonga">(GMT-10:00) Rarotonga</option>
<option value="Pacific/Tahiti">(GMT-10:00) Tahiti</option>
<option value="Pacific/Marquesas">(GMT-09:30) Marquesas</option>
<option value="America/Anchorage">(GMT-09:00) Alaska Time</option>
<option value="Pacific/Gambier">(GMT-09:00) Gambier</option>
<option value="America/Los_Angeles">(GMT-08:00) Pacific Time</option>
<option value="America/Tijuana">(GMT-08:00) Pacific Time - Tijuana</option>
<option value="America/Vancouver">(GMT-08:00) Pacific Time - Vancouver</option>
<option value="America/Whitehorse">(GMT-08:00) Pacific Time - Whitehorse</option>
<option value="Pacific/Pitcairn">(GMT-08:00) Pitcairn</option>
<option value="America/Dawson_Creek">(GMT-07:00) Mountain Time - Dawson Creek</option>
<option value="America/Denver">(GMT-07:00) Mountain Time</option>
<option value="America/Edmonton">(GMT-07:00) Mountain Time - Edmonton</option>
<option value="America/Hermosillo">(GMT-07:00) Mountain Time - Hermosillo</option>
<option value="America/Mazatlan">(GMT-07:00) Mountain Time - Chihuahua, Mazatlan</option>
<option value="America/Phoenix">(GMT-07:00) Mountain Time - Arizona</option>
<option value="America/Yellowknife">(GMT-07:00) Mountain Time - Yellowknife</option>
<option value="America/Belize">(GMT-06:00) Belize</option>
<option value="America/Chicago">(GMT-06:00) Central Time</option>
<option value="America/Costa_Rica">(GMT-06:00) Costa Rica</option>
<option value="America/El_Salvador">(GMT-06:00) El Salvador</option>
<option value="America/Guatemala">(GMT-06:00) Guatemala</option>
<option value="America/Managua">(GMT-06:00) Managua</option>
<option value="America/Mexico_City">(GMT-06:00) Central Time - Mexico City</option>
<option value="America/Regina">(GMT-06:00) Central Time - Regina</option>
<option value="America/Tegucigalpa">(GMT-06:00) Central Time - Tegucigalpa</option>
<option value="America/Winnipeg">(GMT-06:00) Central Time - Winnipeg</option>
<option value="Pacific/Easter">(GMT-06:00) Easter Island</option>
<option value="Pacific/Galapagos">(GMT-06:00) Galapagos</option>
<option value="America/Bogota">(GMT-05:00) Bogota</option>
<option value="America/Cayman">(GMT-05:00) Cayman</option>
<option value="America/Guayaquil">(GMT-05:00) Guayaquil</option>
<option value="America/Havana">(GMT-05:00) Havana</option>
<option value="America/Iqaluit">(GMT-05:00) Eastern Time - Iqaluit</option>
<option value="America/Jamaica">(GMT-05:00) Jamaica</option>
<option value="America/Lima">(GMT-05:00) Lima</option>
<option value="America/Montreal">(GMT-05:00) Eastern Time - Montreal</option>
<option value="America/Nassau">(GMT-05:00) Nassau</option>
<option value="America/New_York">(GMT-05:00) Eastern Time</option>
<option value="America/Panama">(GMT-05:00) Panama</option>
<option value="America/Port-au-Prince">(GMT-05:00) Port-au-Prince</option>
<option value="America/Rio_Branco">(GMT-05:00) Rio Branco</option>
<option value="America/Toronto">(GMT-05:00) Eastern Time - Toronto</option>
<option value="America/Caracas">(GMT-04:30) Caracas</option>
<option value="America/Antigua">(GMT-04:00) Antigua</option>
<option value="America/Asuncion">(GMT-04:00) Asuncion</option>
<option value="America/Barbados">(GMT-04:00) Barbados</option>
<option value="America/Boa_Vista">(GMT-04:00) Boa Vista</option>
<option value="America/Campo_Grande">(GMT-04:00) Campo Grande</option>
<option value="America/Cuiaba">(GMT-04:00) Cuiaba</option>
<option value="America/Curacao">(GMT-04:00) Curacao</option>
<option value="America/Grand_Turk">(GMT-04:00) Grand Turk</option>
<option value="America/Guyana">(GMT-04:00) Guyana</option>
<option value="America/Halifax">(GMT-04:00) Atlantic Time - Halifax</option>
<option value="America/La_Paz">(GMT-04:00) La Paz</option>
<option value="America/Manaus">(GMT-04:00) Manaus</option>
<option value="America/Martinique">(GMT-04:00) Martinique</option>
<option value="America/Port_of_Spain">(GMT-04:00) Port of Spain</option>
<option value="America/Porto_Velho">(GMT-04:00) Porto Velho</option>
<option value="America/Puerto_Rico">(GMT-04:00) Puerto Rico</option>
<option value="America/Santiago">(GMT-04:00) Santiago</option>
<option value="America/Santo_Domingo">(GMT-04:00) Santo Domingo</option>
<option value="America/Thule">(GMT-04:00) Thule</option>
<option value="Antarctica/Palmer">(GMT-04:00) Palmer</option>
<option value="Atlantic/Bermuda">(GMT-04:00) Bermuda</option>
<option value="America/St_Johns">(GMT-03:30) Newfoundland Time - St. Johns</option>
<option value="America/Araguaina">(GMT-03:00) Araguaina</option>
<option value="America/Argentina/Buenos_Aires">(GMT-03:00) Buenos Aires</option>
<option value="America/Bahia">(GMT-03:00) Salvador</option>
<option value="America/Belem">(GMT-03:00) Belem</option>
<option value="America/Cayenne">(GMT-03:00) Cayenne</option>
<option value="America/Fortaleza">(GMT-03:00) Fortaleza</option>
<option value="America/Godthab">(GMT-03:00) Godthab</option>
<option value="America/Maceio">(GMT-03:00) Maceio</option>
<option value="America/Miquelon">(GMT-03:00) Miquelon</option>
<option value="America/Montevideo">(GMT-03:00) Montevideo</option>
<option value="America/Paramaribo">(GMT-03:00) Paramaribo</option>
<option value="America/Recife">(GMT-03:00) Recife</option>
<option value="America/Sao_Paulo">(GMT-03:00) Sao Paulo</option>
<option value="Antarctica/Rothera">(GMT-03:00) Rothera</option>
<option value="Atlantic/Stanley">(GMT-03:00) Stanley</option>
<option value="America/Noronha">(GMT-02:00) Noronha</option>
<option value="Atlantic/South_Georgia">(GMT-02:00) South Georgia</option>
<option value="America/Scoresbysund">(GMT-01:00) Scoresbysund</option>
<option value="Atlantic/Azores">(GMT-01:00) Azores</option>
<option value="Atlantic/Cape_Verde">(GMT-01:00) Cape Verde</option>
<option value="Africa/Abidjan">(GMT+00:00) Abidjan</option>
<option value="Africa/Accra">(GMT+00:00) Accra</option>
<option value="Africa/Bissau">(GMT+00:00) Bissau</option>
<option value="Africa/Casablanca">(GMT+00:00) Casablanca</option>
<option value="Africa/El_Aaiun">(GMT+00:00) El Aaiun</option>
<option value="Africa/Monrovia">(GMT+00:00) Monrovia</option>
<option value="America/Danmarkshavn">(GMT+00:00) Danmarkshavn</option>
<option value="Atlantic/Canary">(GMT+00:00) Canary Islands</option>
<option value="Atlantic/Faroe">(GMT+00:00) Faeroe</option>
<option value="Atlantic/Reykjavik">(GMT+00:00) Reykjavik</option>
<option value="Etc/GMT">(GMT+00:00) GMT (no daylight saving)</option>
<option value="Europe/Dublin">(GMT+00:00) Dublin</option>
<option value="Europe/Lisbon">(GMT+00:00) Lisbon</option>
<option value="Europe/London">(GMT+00:00) London</option>
<option value="Africa/Algiers">(GMT+01:00) Algiers</option>
<option value="Africa/Ceuta">(GMT+01:00) Ceuta</option>
<option value="Africa/Lagos">(GMT+01:00) Lagos</option>
<option value="Africa/Ndjamena">(GMT+01:00) Ndjamena</option>
<option value="Africa/Tunis">(GMT+01:00) Tunis</option>
<option value="Africa/Windhoek">(GMT+01:00) Windhoek</option>
<option value="Europe/Amsterdam">(GMT+01:00) Amsterdam</option>
<option value="Europe/Andorra">(GMT+01:00) Andorra</option>
<option value="Europe/Belgrade">(GMT+01:00) Central European Time - Belgrade</option>
<option value="Europe/Berlin">(GMT+01:00) Berlin</option>
<option value="Europe/Brussels">(GMT+01:00) Brussels</option>
<option value="Europe/Budapest">(GMT+01:00) Budapest</option>
<option value="Europe/Copenhagen">(GMT+01:00) Copenhagen</option>
<option value="Europe/Gibraltar">(GMT+01:00) Gibraltar</option>
<option value="Europe/Luxembourg">(GMT+01:00) Luxembourg</option>
<option value="Europe/Madrid">(GMT+01:00) Madrid</option>
<option value="Europe/Malta">(GMT+01:00) Malta</option>
<option value="Europe/Monaco">(GMT+01:00) Monaco</option>
<option value="Europe/Oslo">(GMT+01:00) Oslo</option>
<option value="Europe/Paris">(GMT+01:00) Paris</option>
<option value="Europe/Prague">(GMT+01:00) Central European Time - Prague</option>
<option value="Europe/Rome">(GMT+01:00) Rome</option>
<option value="Europe/Stockholm">(GMT+01:00) Stockholm</option>
<option value="Europe/Tirane">(GMT+01:00) Tirane</option>
<option value="Europe/Vienna">(GMT+01:00) Vienna</option>
<option value="Europe/Warsaw">(GMT+01:00) Warsaw</option>
<option value="Europe/Zurich">(GMT+01:00) Zurich</option>
<option value="Africa/Cairo">(GMT+02:00) Cairo</option>
<option value="Africa/Johannesburg">(GMT+02:00) Johannesburg</option>
<option value="Africa/Maputo">(GMT+02:00) Maputo</option>
<option value="Africa/Tripoli">(GMT+02:00) Tripoli</option>
<option value="Asia/Amman">(GMT+02:00) Amman</option>
<option value="Asia/Beirut">(GMT+02:00) Beirut</option>
<option value="Asia/Damascus">(GMT+02:00) Damascus</option>
<option value="Asia/Gaza">(GMT+02:00) Gaza</option>
<option value="Asia/Jerusalem">(GMT+02:00) Jerusalem</option>
<option value="Asia/Nicosia">(GMT+02:00) Nicosia</option>
<option value="Europe/Athens">(GMT+02:00) Athens</option>
<option value="Europe/Bucharest">(GMT+02:00) Bucharest</option>
<option value="Europe/Chisinau">(GMT+02:00) Chisinau</option>
<option value="Europe/Helsinki">(GMT+02:00) Helsinki</option>
<option value="Europe/Istanbul">(GMT+02:00) Istanbul</option>
<option value="Europe/Kaliningrad">(GMT+02:00) Moscow-01 - Kaliningrad</option>
<option value="Europe/Kiev">(GMT+02:00) Kiev</option>
<option value="Europe/Riga">(GMT+02:00) Riga</option>
<option value="Europe/Sofia">(GMT+02:00) Sofia</option>
<option value="Europe/Tallinn">(GMT+02:00) Tallinn</option>
<option value="Europe/Vilnius">(GMT+02:00) Vilnius</option>
<option value="Africa/Addis_Ababa">(GMT+03:00) Addis Ababa</option>
<option value="Africa/Asmara">(GMT+03:00) Asmera</option>
<option value="Africa/Dar_es_Salaam">(GMT+03:00) Dar es Salaam</option>
<option value="Africa/Djibouti">(GMT+03:00) Djibouti</option>
<option value="Africa/Kampala">(GMT+03:00) Kampala</option>
<option value="Africa/Khartoum">(GMT+03:00) Khartoum</option>
<option value="Africa/Mogadishu">(GMT+03:00) Mogadishu</option>
<option value="Africa/Nairobi">(GMT+03:00) Nairobi</option>
<option value="Antarctica/Syowa">(GMT+03:00) Syowa</option>
<option value="Asia/Aden">(GMT+03:00) Aden</option>
<option value="Asia/Baghdad">(GMT+03:00) Baghdad</option>
<option value="Asia/Bahrain">(GMT+03:00) Bahrain</option>
<option value="Asia/Kuwait">(GMT+03:00) Kuwait</option>
<option value="Asia/Qatar">(GMT+03:00) Qatar</option>
<option value="Asia/Riyadh">(GMT+03:00) Riyadh</option>
<option value="Europe/Minsk">(GMT+03:00) Minsk</option>
<option value="Europe/Moscow">(GMT+03:00) Moscow+00</option>
<option value="Indian/Antananarivo">(GMT+03:00) Antananarivo</option>
<option value="Indian/Comoro">(GMT+03:00) Comoro</option>
<option value="Indian/Mayotte">(GMT+03:00) Mayotte</option>
<option value="Asia/Tehran">(GMT+03:30) Tehran</option>
<option value="Asia/Baku">(GMT+04:00) Baku</option>
<option value="Asia/Dubai">(GMT+04:00) Dubai</option>
<option value="Asia/Muscat">(GMT+04:00) Muscat</option>
<option value="Asia/Tbilisi">(GMT+04:00) Tbilisi</option>
<option value="Asia/Yerevan">(GMT+04:00) Yerevan</option>
<option value="Europe/Samara">(GMT+04:00) Moscow+00 - Samara</option>
<option value="Indian/Mahe">(GMT+04:00) Mahe</option>
<option value="Indian/Mauritius">(GMT+04:00) Mauritius</option>
<option value="Indian/Reunion">(GMT+04:00) Reunion</option>
<option value="Asia/Kabul">(GMT+04:30) Kabul</option>
<option value="Antarctica/Mawson">(GMT+05:00) Mawson</option>
<option value="Asia/Aqtau">(GMT+05:00) Aqtau</option>
<option value="Asia/Aqtobe">(GMT+05:00) Aqtobe</option>
<option value="Asia/Ashgabat">(GMT+05:00) Ashgabat</option>
<option value="Asia/Dushanbe">(GMT+05:00) Dushanbe</option>
<option value="Asia/Karachi">(GMT+05:00) Karachi</option>
<option value="Asia/Tashkent">(GMT+05:00) Tashkent</option>
<option value="Asia/Yekaterinburg">(GMT+05:00) Moscow+02 - Yekaterinburg</option>
<option value="Indian/Kerguelen">(GMT+05:00) Kerguelen</option>
<option value="Indian/Maldives">(GMT+05:00) Maldives</option>
<option value="Asia/Calcutta">(GMT+05:30) India Standard Time</option>
<option value="Asia/Colombo">(GMT+05:30) Colombo</option>
<option value="Asia/Katmandu">(GMT+05:45) Katmandu</option>
<option value="Antarctica/Vostok">(GMT+06:00) Vostok</option>
<option value="Asia/Almaty">(GMT+06:00) Almaty</option>
<option value="Asia/Bishkek">(GMT+06:00) Bishkek</option>
<option value="Asia/Dhaka">(GMT+06:00) Dhaka</option>
<option value="Asia/Omsk">(GMT+06:00) Moscow+03 - Omsk, Novosibirsk</option>
<option value="Asia/Thimphu">(GMT+06:00) Thimphu</option>
<option value="Indian/Chagos">(GMT+06:00) Chagos</option>
<option value="Asia/Rangoon">(GMT+06:30) Rangoon</option>
<option value="Indian/Cocos">(GMT+06:30) Cocos</option>
<option value="Antarctica/Davis">(GMT+07:00) Davis</option>
<option value="Asia/Bangkok">(GMT+07:00) Bangkok</option>
<option value="Asia/Hovd">(GMT+07:00) Hovd</option>
<option value="Asia/Jakarta">(GMT+07:00) Jakarta</option>
<option value="Asia/Krasnoyarsk">(GMT+07:00) Moscow+04 - Krasnoyarsk</option>
<option value="Asia/Saigon">(GMT+07:00) Hanoi</option>
<option value="Indian/Christmas">(GMT+07:00) Christmas</option>
<option value="Antarctica/Casey">(GMT+08:00) Casey</option>
<option value="Asia/Brunei">(GMT+08:00) Brunei</option>
<option value="Asia/Choibalsan">(GMT+08:00) Choibalsan</option>
<option value="Asia/Hong_Kong">(GMT+08:00) Hong Kong</option>
<option value="Asia/Irkutsk">(GMT+08:00) Moscow+05 - Irkutsk</option>
<option value="Asia/Kuala_Lumpur">(GMT+08:00) Kuala Lumpur</option>
<option value="Asia/Macau">(GMT+08:00) Macau</option>
<option value="Asia/Makassar">(GMT+08:00) Makassar</option>
<option value="Asia/Manila">(GMT+08:00) Manila</option>
<option value="Asia/Shanghai">(GMT+08:00) China Time - Beijing</option>
<option value="Asia/Singapore">(GMT+08:00) Singapore</option>
<option value="Asia/Taipei">(GMT+08:00) Taipei</option>
<option value="Asia/Ulaanbaatar">(GMT+08:00) Ulaanbaatar</option>
<option value="Australia/Perth">(GMT+08:00) Western Time - Perth</option>
<option value="Asia/Dili">(GMT+09:00) Dili</option>
<option value="Asia/Jayapura">(GMT+09:00) Jayapura</option>
<option value="Asia/Pyongyang">(GMT+09:00) Pyongyang</option>
<option value="Asia/Seoul">(GMT+09:00) Seoul</option>
<option value="Asia/Tokyo">(GMT+09:00) Tokyo</option>
<option value="Asia/Yakutsk">(GMT+09:00) Moscow+06 - Yakutsk</option>
<option value="Pacific/Palau">(GMT+09:00) Palau</option>
<option value="Australia/Adelaide">(GMT+09:30) Central Time - Adelaide</option>
<option value="Australia/Darwin">(GMT+09:30) Central Time - Darwin</option>
<option value="Antarctica/DumontDUrville">(GMT+10:00) Dumont D'Urville</option>
<option value="Asia/Magadan">(GMT+10:00) Moscow+08 - Magadan</option>
<option value="Asia/Vladivostok">(GMT+10:00) Moscow+07 - Yuzhno-Sakhalinsk</option>
<option value="Australia/Brisbane">(GMT+10:00) Eastern Time - Brisbane</option>
<option value="Australia/Hobart">(GMT+10:00) Eastern Time - Hobart</option>
<option value="Australia/Sydney">(GMT+10:00) Eastern Time - Melbourne, Sydney</option>
<option value="Pacific/Chuuk">(GMT+10:00) Truk</option>
<option value="Pacific/Guam">(GMT+10:00) Guam</option>
<option value="Pacific/Port_Moresby">(GMT+10:00) Port Moresby</option>
<option value="Pacific/Saipan">(GMT+10:00) Saipan</option>
<option value="Pacific/Efate">(GMT+11:00) Efate</option>
<option value="Pacific/Guadalcanal">(GMT+11:00) Guadalcanal</option>
<option value="Pacific/Kosrae">(GMT+11:00) Kosrae</option>
<option value="Pacific/Noumea">(GMT+11:00) Noumea</option>
<option value="Pacific/Pohnpei">(GMT+11:00) Ponape</option>
<option value="Pacific/Norfolk">(GMT+11:30) Norfolk</option>
<option value="Asia/Kamchatka">(GMT+12:00) Moscow+08 - Petropavlovsk-Kamchatskiy</option>
<option value="Pacific/Auckland">(GMT+12:00) Auckland</option>
<option value="Pacific/Fiji">(GMT+12:00) Fiji</option>
<option value="Pacific/Funafuti">(GMT+12:00) Funafuti</option>
<option value="Pacific/Kwajalein">(GMT+12:00) Kwajalein</option>
<option value="Pacific/Majuro">(GMT+12:00) Majuro</option>
<option value="Pacific/Nauru">(GMT+12:00) Nauru</option>
<option value="Pacific/Tarawa">(GMT+12:00) Tarawa</option>
<option value="Pacific/Wake">(GMT+12:00) Wake</option>
<option value="Pacific/Wallis">(GMT+12:00) Wallis</option>
<option value="Pacific/Apia">(GMT+13:00) Apia</option>
<option value="Pacific/Enderbury">(GMT+13:00) Enderbury</option>
<option value="Pacific/Fakaofo">(GMT+13:00) Fakaofo</option>
<option value="Pacific/Tongatapu">(GMT+13:00) Tongatapu</option>
<option value="Pacific/Kiritimati">(GMT+14:00) Kiritimati</option>

现在在PHP中,您可以使用从选择框中存储的值,并直接输入到时区集中。

date_default_timezone_set($time_zone_name);

用户现在可以选择他们在本地知道的时区。我知道它可以很多,但有一些方法可以做到没有偏移。