doddsey_65 Posted May 4, 2011 Share Posted May 4, 2011 im setting up timezones so every user will be able to have the times displayed in their timezone. however when they register their timezone is sent to the database as an integer value: eg/ -3. meaning -3 hours from GMT. but to set the timezone in php i am using: date_default_timezone_set(); i have the list of available timezones but they just display the names and not the hour difference. Is there any where to get such a list or should i be doing things differently? Quote Link to comment https://forums.phpfreaks.com/topic/235547-timezones/ Share on other sites More sharing options...
requinix Posted May 4, 2011 Share Posted May 4, 2011 The best way I know is to keep a list of timezone names => offsets, then pick the name for the appropriate offset. Problem is that it might not do DST correctly. The second best is with the deprecated "Etc/GMT+X" name. Don't know when it will go away, though. Quote Link to comment https://forums.phpfreaks.com/topic/235547-timezones/#findComment-1210586 Share on other sites More sharing options...
doddsey_65 Posted May 4, 2011 Author Share Posted May 4, 2011 I have an array with a list of timezones and their offsets but the names of the timezones(which i got off my OS's clock) dont match the timezone names in php. Heres my array: $tz = array( "0" => "Select A Timezone", "-12" => "(GMT - 12:00) International Date Line West", "-11" => "(GMT - 11:00) Midway Island, Samoa", "-10" => "(GMT - 10:00) Hawaii", "-9" => "(GMT - 09:00) Alaska", "-8" => "(GMT - 08:00) Pacific Time US, Canada, Baja", "-7" => "(GMT - 07:00) Mountain Time US", "-6" => "(GMT - 06:00) Central America, Mexico City", "-5" => "(GMT - 05:00) Eastern Time US, Bogota, Lima, Quito", "-4:30" => "(GMT - 04:30) Caracas", "-4" => "(GMT - 04:00) Atlantic Time Canada, La Paz, Santiago", "-3:30" => "(GMT - 03:30) Newfoundland", "-3" => "(GMT - 03:00) Brazil, Buenos Aires, Fortaleza, Greenland", "-2" => "(GMT - 02:00) Mid-Atlantic", "-1" => "(GMT - 01:00) Azores, Cape Verde Island", "0" => "(GMT) Western Europe Time, Casablanca, Lisbon, London", "+1" => "(GMT + 01:00) Brussles, Copenhagen, Madrid, Paris, Vienna", "+2" => "(GMT + 02:00) Kaliningrad, South Africa, Cairo", "+3" => "(GMT + 03:00) Baghdad, Riyadh, Moscow, St. Petersberg", "+3:30" => "(GMT + 03:30) Tehran", "+4" => "(GMT + 04:00) Abu Dhabi, Muscat, Yerevan, Baku, Tbilisi", "+4:30" => "(GMT + 04:30) Kabul", "+5" => "(GMT + 05:00) Ekateringberg, Islamabad, Karachi, Tashkent", "+5:30" => "(GMT + 05:30) Mumbai, Kolkata, Chennai, New Delhi", "+5:45" => "(GMT + 05:45) Kathmandu", "+6" => "(GMT + 06:00) Almaty, Dhaka, Colombo", "+6:30" => "(GMT + 06:30) Yangon, Cocos Islands", "+8" => "(GMT + 08:00) Beijing, Perth, Singapore, hong Kong", "+9" => "(GMT + 09:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk", "+9:30" => "(GMT + 09:30) Adelaide, Darwin", "+10" => "(GMT + 10:00) Eastern Australia, Guam, Vladivostok", "+11" => "(GMT + 11:00) Magadan, Solomon Islands, New Caledonia", "+12" => "(GMT + 12:00) Auckland, Wellington, Fiji, Kamchatka", ); Quote Link to comment https://forums.phpfreaks.com/topic/235547-timezones/#findComment-1210589 Share on other sites More sharing options...
gizmola Posted May 4, 2011 Share Posted May 4, 2011 There is a function that will return you all the timezones. I personally save the timezone string and there is a seperate timezone object that you can create and then pass to the various date routines to facilitate conversion. Make sure that your server is configured to use GMT and that you are always storing GMT then use the user's timezone to change the time when you need to display it to them. $tzs = DateTimeZone::listIdentifiers(); Quote Link to comment https://forums.phpfreaks.com/topic/235547-timezones/#findComment-1210591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.