The DateTimeZone class
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
简介
Representation of time zone.
类摘要
class DateTimeZone
{
/* 常量 */
/* 方法 */
public getTransitions(int
}$timestampBegin
= PHP_INT_MIN
, int $timestampEnd
= PHP_INT_MAX
): array|false预定义常量
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.
目录
- DateTimeZone::__construct — 创建新的DateTimeZone对象
- DateTimeZone::getLocation — 返回与时区相关的定位信息。
- DateTimeZone::getName — 返回时区名称。
- DateTimeZone::getOffset — 返回相对于 GMT 的时差。
- DateTimeZone::getTransitions — Returns all transitions for the timezone
- DateTimeZone::listAbbreviations — 返回一个包含 dst (夏令时),时差和时区信息的关联数组。
- DateTimeZone::listIdentifiers — 返回一个包含了所有时区标示符的索引数组。
add a note
User Contributed Notes 2 notes
bradm at inmotionhosting dot com ¶
4 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
)
ryan at amst dot com ¶
6 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.