The DateTimeZone class
(PHP 5 >= 5.2.0)
Introduction
Representation of time zone.
Class synopsis
DateTimeZone
{
/* Constants */
/* Methods */
}Predefined Constants
DateTimeZone::AFRICA
-
Africa time zones.
DateTimeZone::AMERICA
-
America time zones.
DateTimeZone::ANTARCTICA
-
Antarctica time zones.
DateTimeZone::ARCTIC
-
Arctic time zones.
DateTimeZone::ASIA
-
Asia time zones.
DateTimeZone::ATLANTIC
-
Atlantic time zones.
DateTimeZone::AUSTRALIA
-
Australia time zones.
DateTimeZone::EUROPE
-
Europe time zones.
DateTimeZone::INDIAN
-
Indian time zones.
DateTimeZone::PACIFIC
-
Pacific time zones.
DateTimeZone::UTC
-
UTC time zones.
DateTimeZone::ALL
-
All time zones.
DateTimeZone::ALL_WITH_BC
-
All time zones including backwards compatible.
DateTimeZone::PER_COUNTRY
-
Time zones per country.
Table of Contents
- DateTimeZone::__construct — Creates new DateTimeZone object
- DateTimeZone::getLocation — Returns location information for a timezone
- DateTimeZone::getName — Returns the name of the timezone
- DateTimeZone::getOffset — Returns the timezone offset from GMT
- DateTimeZone::getTransitions — Returns all transitions for the timezone
- DateTimeZone::listAbbreviations — Returns associative array containing dst, offset and the timezone name
- DateTimeZone::listIdentifiers — Returns a numerically indexed array containing all defined timezone identifiers
Коментарии
Example of converting between timezones using the DateTime and DateTimeZone classes.
Note that PHP will also take care of calculating relevant daylight savings!
<?php
$utc_timezone = new DateTimeZone("UTC");
$tallinn_timezone = new DateTimeZone("Europe/Tallinn");
// Create a new DateTime object in the UTC format
$datetime = new DateTime("2023-01-01 11:00:00", $utc_timezone);
// Convert the DateTime object to the timezone of Tallinn
$datetime->setTimezone($tallinn_timezone);
// Display the result in the YYYY-MM-DD HH:MM:SS format
echo $datetime->format('Y-m-d H:i:s');
// Returns: 2023-01-01 13:00:00
?>