Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active November 25, 2024 13:12
Show Gist options
  • Save vielhuber/d4b45ba4d7fde1eebca1d6a1a00010c3 to your computer and use it in GitHub Desktop.
Save vielhuber/d4b45ba4d7fde1eebca1d6a1a00010c3 to your computer and use it in GitHub Desktop.
output utc datetime in local time timezone #php
$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