(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DateTimeZone::getTransitions -- timezone_transitions_get — 返回时区的所有转换
面向对象风格
$timestampBegin
= PHP_INT_MIN
, int $timestampEnd
= PHP_INT_MAX
): array|false过程式风格
$object
, int $timestampBegin
= PHP_INT_MIN
, int $timestampEnd
= PHP_INT_MAX
): array|false如果成功,则返回一个以数字为索引的转换数组,否则返回 false
。包裹类型 1(UTC 偏移量)和类型 2(缩写)的 DateTimeZone 对象不包含任何转换,并且在它们上调用此方法将返回 false
。
如果提供了 timestampBegin
,则返回的数组中的第一个条目将包含 timestampBegin
时刻的转换元素。
键 | 类型 | 描述 |
---|---|---|
ts |
int | Unix 时间戳 |
time |
string | DateTimeInterface::ISO8601_EXPANDED (PHP 8.2 及更高版本),或 DateTimeInterface::ISO8601 (PHP 8.1 及更低版本) 时间字符串 |
offset |
int | 到 UTC 的偏移量,以秒为单位 |
isdst |
bool | 是否启用了夏令时 |
abbr |
string | 时区缩写 |
示例 #1 一个 timezone_transitions_get() 示例
<?php
$timezone = new DateTimeZone("Europe/London");
$transitions = $timezone->getTransitions();
print_r(array_slice($transitions, 0, 3));
?>
上面的示例将输出类似以下内容
Array ( [0] => Array ( [ts] => -9223372036854775808 [time] => -292277022657-01-27T08:29:52+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) [1] => Array ( [ts] => -1691964000 [time] => 1916-05-21T02:00:00+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) [2] => Array ( [ts] => -1680472800 [time] => 1916-10-01T02:00:00+0000 [offset] => 0 [isdst] => [abbr] => GMT ) )
示例 #2 一个 timezone_transitions_get() 示例,其中 timestampBegin
设置
<?php
$timezone = new DateTimeZone("Europe/London");
$transitions = $timezone->getTransitions(time());
print_r(array_slice($transitions, 0, 3));
?>
上面的示例将输出类似以下内容
Array ( [0] => Array ( [ts] => 1654184161 [time] => 2022-06-02T15:36:01+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) [1] => Array ( [ts] => 1667091600 [time] => 2022-10-30T01:00:00+0000 [offset] => 0 [isdst] => [abbr] => GMT ) [2] => Array ( [ts] => 1679792400 [time] => 2023-03-26T01:00:00+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) )