Last active
November 25, 2024 13:12
-
-
Save vielhuber/d4b45ba4d7fde1eebca1d6a1a00010c3 to your computer and use it in GitHub Desktop.
output utc datetime in local time timezone #php
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
$date_in_utc = '2024-01-01 12:00:00'; | |
// this both outputs "2024-01-01 13:00:00" | |
date('Y-m-d H:i:s', strtotime($date_in_utc . ' UTC')); | |
(new \DateTime($date_in_utc, new \DateTimeZone('UTC')))->setTimezone(new \DateTimeZone(date_default_timezone_get()))->format('Y-m-d H:i:s')); | |
Carbon::createFromFormat('Y-m-d H:i:s', $date_in_utc, 'UTC')->setTimezone(date_default_timezone_get())->toDateTimeString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment