The DateTimeZone Class

The DateTimeZone class allows you to work with time zones in PHP. It accepts a string with a time zone identifier in its constructor.

Syntax

phpnew DateTimeZone(string $timezone);

Example

Let's create a time zone object for Moscow:

php<?php
  $timezone = new DateTimeZone('Europe/Moscow');
  print_r($timezone);
?>

Code execution result:

phpDateTimeZone Object
(
  'timezone_type' => 3
  'timezone' => Europe/Moscow
)

Example

Usage with the DateTime class:

php<?php
  $timezone = new DateTimeZone('America/New_York');
  $date = new DateTime('now', $timezone);
  echo $date->format('Y-m-d H:i:s');
?>

Code execution result (current time in New York):

php'2025-06-15 14:30:00'

Example

Getting a list of all available time zones:

php<?php
  $timezones = DateTimeZone::listIdentifiers();
  print_r(array_slice($timezones, 0, 5));
?>

Code execution result:

php[
  'Africa/Abidjan'
  'Africa/Accra'
  'Africa/Addis_Ababa'
  'Africa/Algiers'
  'Africa/Asmara'
]

Example

Getting the time zone offset from UTC:

php<?php
  $timezone = new DateTimeZone('Asia/Tokyo');
  echo $timezone->getOffset($date) / 3600;
?>

Code execution result:

php9

See Also