php datetime returning wrong date

Asked

Viewed 45 times

0

Until last midnight the code

$atual = new DateTime("now", new DateTimeZone($timezone));

returned the normal schedule, same as the server, but today presented something strange.

2020-11-01 09:00:30 :: America/Rio_branco
2020-11-01 10:00:30 :: America/Manaus
2020-11-01 11:00:30 :: America/Bahia
2020-11-01 11:00:30 :: America/Fortaleza
2020-11-01 11:00:30 :: America/Cuiaba
2020-11-01 11:00:30 :: America/Campo_Grande
2020-11-01 11:00:30 :: America/Belem
2020-11-01 11:00:30 :: America/Recife
2020-11-01 10:00:30 :: America/Porto_Velho
2020-11-01 10:00:30 :: America/Boa_Vista
2020-11-01 11:00:30 :: America/Maceio
2020-11-01 12:00:30 :: America/Sao_Paulo

Timezone is correct on the server, utc -03:00, and the time displayed by OS tbm.

But some of the timezones are wrong. What can be done to fix it?

Current time of server when I ran script :: (utc -03:00) :: 2020-11-01 11:00:30

Script to test the error.

function GetDates()
{
    $timezones = array(
        'AC' => 'America/Rio_branco',   'AM' => 'America/Manaus',
        'BA' => 'America/Bahia',        'CE' => 'America/Fortaleza',
        'MT' => 'America/Cuiaba',       'MS' => 'America/Campo_Grande',
        'PA' => 'America/Belem',
        'PE' => 'America/Recife',       'RO' => 'America/Porto_Velho',
        'RR' => 'America/Boa_Vista', 
        'SE' => 'America/Maceio',       'SP' => 'America/Sao_Paulo'   
    );
    $format = "Y-m-d H:i:s";                    

    foreach($timezones as $tz)
    {
        $serverTime = new DateTime("now", new DateTimeZone($tz));
        echo "<br>".$serverTime->format($format)." :: $tz";
    }

}

GetDates();
  • Wrong daylight saving time setting?

  • I believe it is, but I don’t know exactly what to look for, no . ini I found nothing related to dst or daylight saving

  • Are you back to normal? Here it seems to be all right.2020-11-02 03:34:36 :: utc 2020-11-02 00:34:36 :: America/Sao_paulo 2020-11-01 23:34:36 :: America/Manaus 2020-11-01 22:34:36 :: America/rio_white

  • No, surely you have something with the php files that manage the daylight saving time of my machine, for now I made a gambiarra for all gmt -3 use the schedule of Bahia and the use -4 of the amazon

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.