Created
October 18, 2016 11:19
-
-
Save thlor/aaffffd65458a5bfb418ae53149b649b to your computer and use it in GitHub Desktop.
new \DateTime() returns an object where the timezone is already set to the user's time zone.
This file contains 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 | |
$time = new \DateTime(); | |
$default = $time->format('d.m.Y H:i'); | |
// 18.10.2016 12:17 | |
$user_timezone = drupal_get_user_timezone(); | |
$timezone = new \DateTimeZone($user_timezone); | |
$time->setTimezone($timezone); | |
$with_user_timezone = $time->format('d.m.Y H:i'); | |
// 18.10.2016 12:17 | |
$timezone = new \DateTimeZone('UTC'); | |
$time->setTimezone($timezone); | |
$with_utc_timezone = $time->format('d.m.Y H:i'); | |
// 18.10.2016 11:17 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment