Класс DateTimeZone

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

Введение

Представление временной зоны.

Обзор классов

DateTimeZone {
/* Константы */
const int AFRICA = 1 ;
const int AMERICA = 2 ;
const int ANTARCTICA = 4 ;
const int ARCTIC = 8 ;
const int ASIA = 16 ;
const int ATLANTIC = 32 ;
const int AUSTRALIA = 64 ;
const int EUROPE = 128 ;
const int INDIAN = 256 ;
const int PACIFIC = 512 ;
const int UTC = 1024 ;
const int ALL = 2047 ;
const int ALL_WITH_BC = 4095 ;
const int PER_COUNTRY = 4096 ;
/* Методы */
public __construct(string $timezone)
public getLocation(): array|false
public getName(): string
public getOffset(DateTimeInterface $datetime): int
public getTransitions(int $timestampBegin = PHP_INT_MIN, int $timestampEnd = PHP_INT_MAX): array|false
public static listAbbreviations(): array
public static listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, string|null $countryCode = null): array
}

Предопределённые константы

DateTimeZone::AFRICA

Временные зоны Африки.

DateTimeZone::AMERICA

Временные зоны Америки.

DateTimeZone::ANTARCTICA

Временные зоны Антарктики.

DateTimeZone::ARCTIC

Временные зоны Арктики.

DateTimeZone::ASIA

Временные зоны Азии.

DateTimeZone::ATLANTIC

Временные зоны Атлантики.

DateTimeZone::AUSTRALIA

Временные зоны Австралии.

DateTimeZone::EUROPE

Временные зоны Европы.

DateTimeZone::INDIAN

Временные зоны Индии.

DateTimeZone::PACIFIC

Временные зоны Тихого океана.

DateTimeZone::UTC

Временная зона UTC.

DateTimeZone::ALL

Все временные зоны.

DateTimeZone::ALL_WITH_BC

Все временные зоны, включая обратно совместимые.

DateTimeZone::PER_COUNTRY

Временных зон на страну.

Содержание

  • DateTimeZone::__construct — Создаёт новый объект DateTimeZone
  • DateTimeZone::getLocation — Возвращает информацию о местоположении для временной зоны
  • DateTimeZone::getName — Возвращает имя временной зоны
  • DateTimeZone::getOffset — Возвращает смещение временной зоны от UTC (GMT)
  • DateTimeZone::getTransitions — Возвращает все переходы для временной зоны
  • DateTimeZone::listAbbreviations — Возвращает ассоциативный массив, содержащий флаг перехода на летнее время, смещение и имя временной зоны
  • DateTimeZone::listIdentifiers — Возвращает численно-индексированный массив со всеми идентификаторами временных зон
add a note add a note

User Contributed Notes 2 notes

up
3
bradm at inmotionhosting dot com
6 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
-22
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