Created
September 16, 2019 09:25
-
-
Save kobus1998/a2caf5ffb32a62655416483ed282feea to your computer and use it in GitHub Desktop.
Manage user timezones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $timezones = []; | |
| foreach(DateTimeZone::listIdentifiers() as $timezone) | |
| { | |
| $timezoneWithContinent = explode('/', $timezone); | |
| if (count($timezoneWithContinent) == 1) { | |
| // skip UTC | |
| continue; | |
| } | |
| $timezones[$timezoneWithContinent[0]][$timezoneWithContinent[1]] = $timezone; | |
| } | |
| // add timezone in select as preference | |
| $date = new DateTime('now', new DateTimeZone($timezones['Europe']['Amsterdam'])); | |
| echo $date->format('c'); // 2019-09-16T11:24:37+02:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment