Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created September 16, 2019 09:25
Show Gist options
  • Save kobus1998/9450bae5481d9e0d7c9c77d789ba67a3 to your computer and use it in GitHub Desktop.
Save kobus1998/9450bae5481d9e0d7c9c77d789ba67a3 to your computer and use it in GitHub Desktop.
Manage user timezones
<?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