3

Hopefully someone notices what is the cause for the problem I'm having.

For all other timezones such as "Europe/Helsinki" the offset calculation below returns correct values, but for some reason I get negative value for 'Etc/GMT+2' style timezones and vice versa (e.g. for Etc/GMT-2 I get positive value, 7200).

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

Expected: 7200 Result: -7200

2 Answers 2

5

The Etc/GMT+2 timezone is what would otherwise be called "GMT -2" or represented like <date time>-02:00.

This is due to the way that POSIX represents those types of timezone offsets:

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.

And:

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.

Sign up to request clarification or add additional context in comments.

Comments

1

From http://www.php.net/manual/en/timezones.others.php#64310

The plus and minus signs (+/-) are not intuitive. For example,

"Etc/GMT-10" actually refers to the timezone "(GMT+10:00) Canberra,Sydney,Melbourne".

1 Comment

Thanks. Even though I investigated this a bit, just after posting my question I ended up to the same page: "All *nix system has this problem: ETC/GMT-10 means GMT+10:00,php just use the rules of *nix" explained"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.