PHP timezone, etc. / GMT + 5 becomes -0500?

As with many web apps, the app I'm developing should work with timezone conversion for our esteemed end users. However, since I was working with Carbon / DateTime in PHP 5.3, I found this strange:

$date_str = '2014-04-15 12:00:00'; // from database

$date = new DateTime($date_str,new DateTimeZone('GMT'));
$date->setTimezone(new DateTimeZone('Etc/GMT+5'));

echo $date->format('Y-m-d H:i:s O'); // 2014-04-15 07:00:00 -0500

I set the time zone $dateto GMT + 5, but when I format $date, it becomes -0500instead of the expected one +0500.

Similarly, if I set it to negative, i.e. Etc/GMT-5, format shows +0500instead of expected -0500.

Anyone who can educate?

I was able to replicate this problem in PHP 5.3.3, 5.3.13, 5.3.28. Thought it was a bug of the PHP-specific version. Error or function?

+4
2

. Etc/GMT .

tz:

POSIX, , Etc/GMT, , , . GMT , (, Etc/GMT-14 14 / GMT).

PHP :

: , - , ( UTC), .


. , print_r(DateTimeZone::listIdentifiers(DateTimeZone::ALL));.

+6

, .

.. /GMT

gtm + offset

$date_str = '2014-04-15 12:00:00'; // from database

$date = new DateTime($date_str,new DateTimeZone('GMT'));
$date->setTimezone(new DateTimeZone('GMT+5'));

echo $date->format('Y-m-d H:i:s O'); 

2014-04-15 17:00:00 +0500

0

Source: https://habr.com/ru/post/1538164/


All Articles