Converting time in php and converting it on google shows different results which is correct?

Viewed 39

I converted the time 18:00:00 pm UTC time to Los angeles time and the output of the program was 10 AM and then I searched this on google "18:00:00 pm UTC to Los angeles time" and google showed me the result 11:00 AM https://i.imgur.com/H5po3fD.png I am confused whats correct here. Similarly if I convert converted_date_time('2021-11-08 04:54:15') UTC to los angles time then the program output shows the time 8:54 AM but on google it shows 9:54 AM.

date_default_timezone_set("America/Los_Angeles");
echo date_default_timezone_get();
echo '<br>';

function converted_date_time($dt) {
        $datetime = new DateTime($dt, new DateTimeZone('UTC'));
      $datetime->format('Y-m-d H:i:s');
      $datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));
      return $datetime->format('Y-m-d H:i:s');
}


//convert time to utc
echo converted_date_time('2021-11-08 18:00:00').'<br>';
1 Answers

It depends on the date. Daylight savings don't apply to UTC, so in summer, 18:00 UTC will be 11:00 Pacific Time (PDT, Pacific Daylight Time), while in winter, 18:00 UTC will be 10:00 Pacific Time (PST, Pacific Standard Time). Most likely Google shows you the current result (with Daylight Savings, so +1 hour), while at your date (November 8), daylight savings is off.

In other words, today, 18:00 UTC is 11:00 in Los Angeles, but next month, 18:00 UTC will be 10:00 in Los Angeles. You can try by yourself, those two should give you different results:

echo converted_date_time('2021-11-08 18:00:00').'<br>';
echo converted_date_time('2021-09-08 18:00:00').'<br>';
Related