Класс DateTimeZone

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

Введение

Представление часового пояса.

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

class DateTimeZone {
/* Константы */
public const int AFRICA;
public const int AMERICA;
public const int ANTARCTICA;
public const int ARCTIC;
public const int ASIA;
public const int ATLANTIC;
public const int AUSTRALIA;
public const int EUROPE;
public const int INDIAN;
public const int PACIFIC;
public const int UTC;
public const int ALL;
public const int ALL_WITH_BC;
public const int PER_COUNTRY;
/* Методы */
public __construct(string $timezone)
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 $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
10
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
-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