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 add a note

User Contributed Notes 2 notes

up
10
bradm at inmotionhosting dot com
5 years ago
Seems like a significant differences between php 5.3 and 5.6:

php -r "new DateTimeZone( '-0400' );"
-------------                        --------------
- PHP 5.3.3 -                        - PHP 5.6.30 -
-------------                        --------------
DateTimeZone::__construct():        Works as expected.
Unknown or bad timezone (-0400)

php -r '$tz = new DateTimeZone( "EDT" ); echo $tz->getName();';
-------------                        --------------
- PHP 5.3.3 -                        - PHP 5.6.30 -
-------------                        --------------
America/New_York                    EDT

php -r '$tz = new DateTimeZone( "EDT" ); echo $tz->getName();';
-------------                        --------------
- PHP 5.3.3 -                        - PHP 5.6.30 -
-------------                        --------------
DateTimeZone Object                DateTimeZone Object
(                                    (
)                                    [timezone_type] => 2
                                    [timezone] => EDT
                                    )
up
-38
ryan at amst dot com
8 years ago
It seems like as of PHP 5.5, creating a new DateTimeZone with a string like 'EDT' will cause DateTimeZone::getName() to return 'EDT' whereas prior to 5.5 it would convert it would have returned 'America/New_York'

This is of particular note when using a DateTimeZone object to change the timezone on a DateTime object.  Using a DateTimeZone object when set as shown above will cause the conversion to be wrong without throwing any errors.
To Top