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

mathewparet's avatar

Wrong timezone returned by Laravel API, while tinker shows correct time

I have a problem with date in my Laravel projects - the date in the DB is not the date returned via api.

When I fetch the record from tinker, the updated_date is 2020-03-23 19:22:47. This is correct as per my timzone and the time when the event happened.

mathewparet$ php artisan tinker
Psy Shell v0.10.0 (PHP 7.3.11 — cli) by Justin Hileman
>>> App\User::find(4);
=> App\User {#3076
     id: "4",
     name: "Normal User",
     email: "[email protected]",
     email_verified_at: "2020-03-23 19:22:47",
     created_at: "2020-03-23 19:21:44",
     updated_at: "2020-03-23 19:22:47",
   }
>>> exit
Exit:  Goodbye
mathewparet$ 

I use the below code to retrieve the data in my controller and send to the browser as JSON:

public function index(Request $request)
{
        $this->authorize('viewAny', User::class);
        
        $users = User::all();

        return compact('users');
}

However, the output, when caught at the browser end shows a different date:

Screenshot from chrome Dev Tools

The app timezone is set as:

'timezone' => 'Australia/Sydney',

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Your timestamps are in UTC, but also in ISO8601, the standard for XML - where are they getting converted to ISO format?

1 like
mathewparet's avatar

You gave me the clue. It looks like API always returns UTC when response is JSON

1 like

Please or to participate in this conversation.