gpt4 book ai didi

php - 获取即将到来的夏令时日期

转载 作者:可可西里 更新时间:2023-11-01 00:55:19 26 4
gpt4 key购买 nike

如何通过 PHP 获取特定时区即将到来的夏令时日期/时间更改?我想输出例如:

Upcoming clock change for Berlin will be on 29.10.2017 at 3am.

最佳答案

$date = new DateTime();
$tz = $date->getTimezone();
$changes = $tz->getTransitions(strtotime("yesterday"), strtotime("+1 year"));
$n = count($changes);
$tnow = time();
for($i = 0; $i < $n; $i++)
{
if($changes[$i]["ts"] > $tnow)
{
echo "Upcoming clock change for " . $tz->getName() . " will be on " . $changes[$i]["time"] . "\n";
break;
}
}

关于php - 获取即将到来的夏令时日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46958720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com