jeudi 2 décembre 2021

Laravel Timezone doesn't convert to the correct timezone in Laravel

I am trying to build a simple function where I want to fetch a DateTime from database that is stored in UTC format and display it to the user in their local timezone. I found heaps of solutions that works, but the timezone is not correct.

 $time = Carbon::createFromFormat('Y-m-d H:i:s', $user->created_at)->settings(['timezone' => 'Australia/Sydney']);

So this code takes in $user->created_at , "created_at": "2021-12-02T21:18:31.000000Z", which in UTC format created on 21:18, which is 8:18 am in Sydney, yet, when I run the code i get a wrong time zone, "2021-12-02T10:27:29.000000Z", which is 10:27 am.

I am not sure whats happening. Any Help will be greatly appreciated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire