Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DDSameera's avatar

UTC time convert to Local one in Laravel 8

How can i convert following time into Sri Lanka time.

"recording_start" => "2021-02-26T03:49:20Z"
  "recording_end" => "2021-02-26T03:49:26Z"

I tried. this one not works

     $recordingStart = \Carbon\Carbon::parse($recordingStart)->toDateTimeString();
  $recordingStart = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $recordingStart, 'Asia/Colombo');
dd($recordingStart);
0 likes
2 replies
shami003's avatar

If you want to chage timezone for the whole app you have to change it in config.app file 'timezone' => 'Asia/Colombo'

This will also change created_at, updated_at time to the mentioned timezone

tykus's avatar
tykus
Best Answer
Level 104

Use setTimezone on the Carbon instance, e.g.

\Carbon\Carbon::parse("2021-02-26T03:49:20Z")->setTimezone('Asia/Colombo')->toDateTimeString();
// => "2021-02-26 09:19:20"
1 like

Please or to participate in this conversation.