The getTimezone Method of the DateTime Class

The getTimezone method returns a DateTimeZone object, representing the time zone set for the DateTime object. If the time zone is not set, the default time zone will be returned.

Syntax

phppublic DateTime::getTimezone(): DateTimeZone|false

Example

Get the time zone for the current date:

php<?php
  $date = new DateTime();
  $timezone = $date->getTimezone();
  echo $timezone->getName();
?>

Code execution result (depends on server settings):

php'Europe/Moscow'

Example

Set the time zone and check it:

php<?php
  $date = new DateTime('now', new DateTimeZone('America/New_York'));
  $timezone = $date->getTimezone();
  echo $timezone->getName();
?>

Code execution result:

php'America/New_York'

See Also