PHP 8.1.31 Released!

La clase DateTimeZone

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

Introducción

Representación de la zona horaria.

Sinopsis de la Clase

class DateTimeZone {
/* Constantes */
const integer AFRICA = 1;
const integer AMERICA = 2;
const integer ANTARCTICA = 4;
const integer ARCTIC = 8;
const integer ASIA = 16;
const integer ATLANTIC = 32;
const integer AUSTRALIA = 64;
const integer EUROPE = 128;
const integer INDIAN = 256;
const integer PACIFIC = 512;
const integer UTC = 1024;
const integer ALL = 2047;
const integer ALL_WITH_BC = 4095;
const integer PER_COUNTRY = 4096;
/* Métodos */
public __construct(string $timezone)
public getLocation(): array
public getName(): string
public getOffset(DateTime $datetime): int
public getTransitions(int $timestamp_begin = PHP_INT_MIN, int $timestamp_end = PHP_INT_MAX): array
public static listAbbreviations(): array
public static listIdentifiers(int $what = DateTimeZone::ALL, string $country = null): array
}

Constantes predefinidas

DateTimeZone::AFRICA

Zonas horarias de África.

DateTimeZone::AMERICA

Zonas horarias de América.

DateTimeZone::ANTARCTICA

Zonas horarias de la Antártida.

DateTimeZone::ARCTIC

Zonas horarias del Ártico.

DateTimeZone::ASIA

Zonas horarias de Asia.

DateTimeZone::ATLANTIC

Zonas horarias del Atlántico.

DateTimeZone::AUSTRALIA

Zonas horarias de Australia.

DateTimeZone::EUROPE

Zonas horarias de Europa.

DateTimeZone::INDIAN

Zonas horarias de la India.

DateTimeZone::PACIFIC

Zonas horarias del Pacífico.

DateTimeZone::UTC

Zonas horarias UTC.

DateTimeZone::ALL

Todas las zonas horarias.

DateTimeZone::ALL_WITH_BC

Todas las zonas horarias incluyendo las de versiones anteriores por compatibilidad.

DateTimeZone::PER_COUNTRY

Zonas horarias por país.

Tabla de contenidos

add a note

User Contributed Notes 1 note

up
1
Jarmo Troska
1 year ago
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

?>
To Top