How to convert a time to another time zone
Short answer
Create the date in its original zone and call setTimezone():
<?php
$utc = new DateTimeImmutable('2026-03-15 12:00', new DateTimeZone('UTC'));
echo $utc->setTimezone(new DateTimeZone('Europe/Paris'))->format('Y-m-d H:i'), "\n";
echo $utc->setTimezone(new DateTimeZone('Asia/Tokyo'))->format('Y-m-d H:i');Output:
2026-03-15 13:00
2026-03-15 21:00Store time in UTC
Time is stored in the database in UTC and converted to the user's zone only for display. The moment in time does not change — only its notation does:
<?php
$utc = new DateTimeImmutable('2026-03-15 12:00', new DateTimeZone('UTC'));
$tokyo = $utc->setTimezone(new DateTimeZone('Asia/Tokyo'));
var_dump($utc == $tokyo);
var_dump($utc->getTimestamp() === $tokyo->getTimestamp());Output:
bool(true)
bool(true)Functions used in this recipe
- DateTimeImmutable — A date and time object that cannot be changed: every operation returns a new object.
- date_default_timezone_set — Sets the time zone for every date function.
- date — Formats a date and time.