Home >PHP >PHP reference – functions >date_timezone_set

date_timezone_set

date_timezone_set($object, $timezone)

Converts a DateTime object to another time zone. The moment (timestamp) stays the same, only the displayed date and time change. It changes the original object and returns it. It is the same as $object->setTimezone($timezone).

Parameters

  • $object – the DateTime object to modify.
  • $timezone – a DateTimeZone object, for example from timezone_open("UTC").

Examples

$d = date_create("2026-10-05 14:00", timezone_open("Europe/Prague"));
date_timezone_set($d, timezone_open("America/New_York"));
echo $d->format("Y-m-d H:i T"); // 2026-10-05 08:00 EDT
// the moment does not change, only the display
$d = date_create("2026-10-05 14:00", timezone_open("Europe/Prague"));
$timestamp = $d->getTimestamp();
date_timezone_set($d, timezone_open("Asia/Tokyo"));
echo $d->format("H:i"); // 21:00
var_dump($timestamp === $d->getTimestamp()); // bool(true)
// time for storing in a database in UTC
echo date_timezone_set(date_create("2026-10-05 14:00", timezone_open("Europe/Prague")), timezone_open("UTC"))->format("Y-m-d H:i:s"); // 2026-10-05 12:00:00
// DateTimeImmutable: the setTimezone method returns a new object
$a = date_create_immutable("2026-10-05 14:00", timezone_open("Europe/Prague"));
echo $a->setTimezone(timezone_open("Asia/Tokyo"))->format("H:i") . " " . $a->format("H:i"); // 21:00 14:00

Things to watch out for

  • The moment stays, only the displayed time changes. The same time “on the clock” in another zone is given by a new object: date_create("2026-10-05 14:00", timezone_open("Asia/Tokyo")).
  • It accepts only DateTime. With DateTimeImmutable, PHP 7.4 outputs a warning and returns false, PHP 8 throws a TypeError exception. For DateTimeImmutable use the setTimezone() method.
  • A proven approach: store time in UTC and convert it to the zone of the visitor only when displaying.

Related functions:
date_timezone_get()
timezone_open()
date_create()
date_format()
date_default_timezone_set()