Reputation: 1048
Currently i have a list of timezone fetched from php $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
which contain 400+ timezone is there any way i can use these timezone list instead of that huge list.
Upvotes: 0
Views: 104
Reputation: 180125
What we do is pick a "representative" timezone for each of the timezones we want to show. So, our drop-down looks something like this:
<select>
<option value="America/New_York">US Eastern Time</option>
<option value="America/Los_Angeles">US Pacific Time</option>
<option value="Asia/Tokyo">Japan Standard Time</option>
<option value="Australia/Sydney">Australia Eastern Time</option>
</select>
The value
part is what we save into the database of the user, but they pick based on the "nicer" names they're likely to be familiar with. This also works better than a GMT offset, as it takes into account things like daylight savings automatically.
Another potential option is having the user pick a country first. If you do that, you can then pass the second optional parameter to listIdentifiers
:
DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'AU')
which will limit the output to just valid timezones within that country:
[
"Antarctica/Macquarie",
"Australia/Adelaide",
"Australia/Brisbane",
"Australia/Broken_Hill",
"Australia/Currie",
"Australia/Darwin",
"Australia/Eucla",
"Australia/Hobart",
"Australia/Lindeman",
"Australia/Lord_Howe",
"Australia/Melbourne",
"Australia/Perth",
"Australia/Sydney",
]
Some will even make it easy on you, and spit out only one timezone, which'll let you guess pretty accurately which timezone that user is likely to be using...
DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'FR')
[
"Europe/Paris",
]
Upvotes: 1