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!