PHP date_timezone_set() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

In PHP, date_timezone_set() changes the timezone of a DateTime object, so the same moment is shown as a clock time in another place.

It is the procedural name for DateTime::setTimezone() (and DateTimeImmutable::setTimezone()). The moment in time stays the same; only the way it is shown changes.

Syntax

Call date_timezone_set() with the values you need. Start with this line.

PHP
date_timezone_set($date, timezone_open("Asia/Kolkata"));
CallWhat it does
date_timezone_set($date, timezone_open("Asia/Kolkata"))Shows the date in India time (UTC+5:30).
date_timezone_set($date, timezone_open("America/New_York"))Shows the date in New York time.
date_timezone_set($date, new DateTimeZone("UTC"))Shows the date in UTC.

This function converts the display time; it does not move the moment in time. The timestamp stays the same. For code that shares dates, use DateTimeImmutable::setTimezone(), which returns a new object and leaves the original alone.

Library declarations
PHP
date_timezone_set(DateTime $object, DateTimeZone $timezone): DateTime

Parameters

ParameterDescription
objectRequired. The DateTime object to change.
timezoneRequired. A DateTimeZone object, created with timezone_open() or new DateTimeZone().

Return Value

Return ValueDescription
DateTimeThe same DateTime object after the timezone has been changed.

PHP Examples

Example 1 — Convert a Time to Other Timezones

Start with 12:00 UTC and show the same moment in India and New York.

PHP
<?php
$date = date_create("2024-01-15 12:00:00", timezone_open("UTC"));

date_timezone_set($date, timezone_open("Asia/Kolkata"));
echo date_format($date, "Y-m-d H:i:s P"), PHP_EOL;

date_timezone_set($date, timezone_open("America/New_York"));
echo date_format($date, "Y-m-d H:i:s P"), PHP_EOL;

How It Works

  1. Create a date at 12:00 in UTC.
  2. Changing the timezone to Asia/Kolkata adds 5 hours 30 minutes, which gives 17:30.
  3. Changing it to America/New_York shows the same moment as 07:00, because New York is 5 hours behind UTC in winter.
  4. The format character P prints the offset for each timezone.

Example 2 — The Moment Stays the Same

Changing the timezone can change the date on the clock, but the timestamp is the same.

PHP
<?php
$date = date_create("2024-01-15 23:00:00", timezone_open("UTC"));
$before = date_timestamp_get($date);

date_timezone_set($date, timezone_open("Asia/Tokyo"));
echo date_format($date, "Y-m-d H:i T"), PHP_EOL;
echo $before === date_timestamp_get($date) ? "Same instant" : "Different instant", PHP_EOL;

How It Works

  1. The date starts at 23:00 on January 15 in UTC, and its timestamp is saved.
  2. Tokyo is 9 hours ahead of UTC, so the clock now shows 08:00 on January 16.
  3. The format character T prints the abbreviation JST.
  4. The timestamp is unchanged, so both times are the same moment.

Example 3 — Meeting Time in Several Cities

Use DateTimeImmutable::setTimezone() to show one meeting time in different cities without changing the original.

PHP
<?php
$meeting = new DateTimeImmutable("2024-07-01 15:00:00", new DateTimeZone("UTC"));

foreach (["Asia/Kolkata", "America/New_York", "Asia/Tokyo"] as $zone) {
    $local = $meeting->setTimezone(new DateTimeZone($zone));
    echo $zone, ": ", $local->format("Y-m-d H:i"), PHP_EOL;
}

How It Works

  1. Create the meeting at 15:00 UTC as a DateTimeImmutable.
  2. Loop over the timezone names and call setTimezone() for each one. Each call returns a new object.
  3. India is 5. 5 hours ahead, New York is 4 hours behind (summer time), and Tokyo is 9 hours ahead.
  4. In Tokyo the meeting falls after midnight, so the date moves to July 2.

Frequently Asked Questions

It changes the timezone of a DateTime object. The moment in time stays the same, but the clock time and date are shown for the new timezone.
No. The timestamp always stays the same because the moment does not change. Only the displayed time changes.
date_timezone_set() changes one date object. date_default_timezone_set() changes the default timezone used by date functions for the whole script.
Yes, for DateTime it does. DateTimeImmutable::setTimezone() returns a new object, which is safer when you share dates.
Yes. It is the procedural alias of setTimezone(), which also exists on DateTimeImmutable.

Next: getdate()

getdate() turns a Unix timestamp into an array that holds the date and time parts, such as.

getdate() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful