gpt4 book ai didi

php - 如何知道当前时间是否为夏令时?

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

我如何知道世界上特定城市的当前时间是否采用夏令时?有PHP函数吗?

最佳答案

我不是 PHP 专家,但看起来这是可行的 - 但很尴尬。

给定一个 DateTimeZone ,您可以找到当前偏移量和一组转换。因此,如果您询问“现在”的转换,您可以找到有关时区当前部分的信息。来自 the docs 的略微修改的示例:

$theTime = time(); # specific date/time we're checking, in epoch seconds. 

$tz = new DateTimeZone('America/Los_Angeles');
$transition = $tz->getTransitions($theTime,$theTime);

# only one array should be returned into $transition.
$dst = $transition[0]['isdst'];

关于php - 如何知道当前时间是否为夏令时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4835839/

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