0

I'm trying to use the accurate current local time for any location in the world based on their "TimezoneId". Somestimes I'm getting the correct GMT offset. For example:

$localTimezone = new DateTimeZone('America/Los_Angeles');
$gmtTimezone = new DateTimeZone('GMT');
$currentDateTime = new DateTime('2020-01-21 13:14', $gmtTimezone);
$offset = $localTimezone ->getOffset($currentDateTime );
echo $offset/3600;

This returns -8 which is correct for today's date in Los Angeles.

However, when I try the same using America/Sao_Paulo as the "TimezoneId" I get -2 which is currently not correct for this location. It should be -3 according to Google and other time apps I have tried.

I've searched for a solution and seen different attemps which don't seem to be working me.

Thank you for your input!

James
  • 458
  • 1
  • 6
  • 18

1 Answers1

3

According to timeanddate.com Brazil stopped observing DST on 17 February 2019. To get that reflected in your application you need a PHP release that includes a version of the IANA Time Zone Database updated after whenever the announcement was made. I've run your code in 3v4l.org and got 7.3.9 - 7.4.1.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • So are you suggesting this depends on the version of PHP I'm using? – James Jan 21 '20 at 14:17
  • 1
    Not exactly. It depends on the IANA Time Zone Database used by your PHP installation. Typically, it'll use the one bundled by PHP creators but I presume that third-party packagers (such as Linux distros) can include a different version. – Álvaro González Jan 21 '20 at 14:19
  • Thanks for the info @Alvaro – James Jan 21 '20 at 14:25