0

Current month convert is OK

    $fromTz = new \DateTimeZone('UTC');
    $toTz = new \DateTimeZone('America/Nipigon');
    $carbonUtoA = Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2020-10-22 17:00:00', $fromTz)->setTimezone($toTz);
    echo $carbonUtoA->format('Y-m-d H:i:s');  // 2020-10-22 13:00:00

    date_default_timezone_set('UTC');
    $dateTime = new DateTime('2020-10-22 17:00:00');
    $toTz = new DateTimeZone('America/Nipigon');
    $dateTime->setTimezone($toTz);
    echo $dateTime->format('Y-m-d H:i:s');  // 2020-10-22 13:00:00

Next month covert is not same as current month

    $fromTz = new \DateTimeZone('UTC');
    $toTz = new \DateTimeZone('America/Nipigon');
    $carbonUtoA = Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2020-11-22 17:00:00', $fromTz)->setTimezone($toTz);
    echo $carbonUtoA->format('Y-m-d H:i:s'); // 2020-11-22 12:00:00

    date_default_timezone_set('UTC');
    $dateTime = new DateTime('2020-11-22 17:00:00');
    $toTz = new DateTimeZone('America/Nipigon');
    $dateTime->setTimezone($toTz);
    echo $dateTime->format('Y-m-d H:i:s'); // 2020-11-22 12:00:00

But it should be same the time as current month 13:00:00 because before convert in UTC the time was same 17:00:00

Awolad Hossain
  • 1,007
  • 13
  • 18
  • 1
    That's because DST ends on November 1st, so the difference between UTC and America/Nipigon will be -5 hours, not -4 hours: https://www.travelmath.com/time-zone/America/Nipigon – kmoser Oct 21 '20 at 16:34
  • DST ends next Sunday here in Europe, we'll be seeing some more questions like this these days :) – Álvaro González Oct 22 '20 at 17:49

0 Answers0