且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查时间偏移是否在夏令时?

更新时间:2022-05-08 07:12:27

您不能仅从偏移量中得出这一点,因为偏移量适用于整个纬度,并且没有统一 DST 生效的国家/地区.例如在澳大利亚,夏令时在昆士兰、北领地或西澳大利亚,但在其他任何地方.您必须定位您的用户,然后使用PHP 的 DateTimeZone API 那个国家是否有夏令时.

You cant derive this from the offset alone because the offset applies to the whole latitude and countries on that do not have uniform DST in effect. For instance in Australia, Daylight Saving Time is not observed in Queensland, the Northern Territory or Western Australia but everywhere else. You'd have to geolocate your users and then check with PHP's DateTimeZone API whether there is DST in that country.

另请参阅如何自动检测用户的时区?