Is it possible to have something like?
$offset = -05:00;
$timezone = getTimeZone($offset); //return America/New_York
date_default_timezone_set($timezone);
How about the DST(Day Saving Light) if yes?
EDIT
What i have tried is
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
But i don't know whether this way is correct or not?
Forgive me from bringing back an old question, but i was having the same issue using the Offset, but instead, decided to use this list. (From Google Calendar)
Instead of storing the offset, store the actual name "America/Phoenix"
This is what I have now for when users select a time zone. Its perfect lineup of the major timezones, and PHP ready. http://php.net/manual/en/timezones.php
Now in PHP you can use the value you stored from the select box, and input directly into the timezone set.
The user would now select a timezone they know locally. I know it can be a lot, but there are ways to do it without the offset.
No, because there's no such reverse correlation. There are many timezones which currently have a
-05:00
offset. That's why you should use timezone identifiers to identify timezones, not offsets.