gpt4 book ai didi

php DateTimeZone->getOffset() 返回 GMT 时区的无效偏移量

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

希望有人注意到我遇到的问题的原因。

对于所有其他时区,例如“欧洲/赫尔辛基”,下面的偏移量计算返回正确的值,但出于某种原因,我得到“Etc/GMT+2”样式时区的负值,反之亦然(例如,对于 Etc/GMT- 2 我得到正值,7200)。

$dateTimeZone = new DateTimeZone('Etc/GMT+2');
echo $dateTimeZone->getOffset(new DateTime("now", new DateTimezone( 'UTC' )));

预期:7200结果:-7200

最佳答案

Etc/GMT+2时区否则将被称为“GMT -2”或表示为 <date time>-02:00 .

这是由于 POSIX 表示这些类型的时区偏移的方式:

The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between 0 and 23, and the minute and seconds between 0 and 59.

From TZ Variable.

和:

Numeric time zone abbreviations typically count hours east of UTC, e.g., +09 for Japan and -10 for Hawaii. However, the POSIX TZ environment variable uses the opposite convention. For example, one might use TZ="JST-9" and TZ="HST10" for Japan and Hawaii, respectively. If the tz database is available, it is usually better to use settings like TZ="Asia/Tokyo" and TZ="Pacific/Honolulu" instead, as this should avoid confusion, handle old time stamps better, and insulate you better from any future changes to the rules. One should never set POSIX TZ to a value like "GMT-9", though, since this would falsely claim that local time is nine hours ahead of UTC and the time zone is called "GMT".

From Sources for Time Zone and Daylight Saving Time Data - Time notation.

关于php DateTimeZone->getOffset() 返回 GMT 时区的无效偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5339547/

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