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

Devio's avatar
Level 2

Set carbon to use my timezone

I have set my timezone in the app config but when I run Carbon::now() I get the UTC time. How can I configure carbon to work with my timezone?

0 likes
12 replies
tykus's avatar

It should work as iexpected; is your config cached?

php artisan config:clear

Where are you having the issue (CLI, web request) / (local/production server)?

1 like
Devio's avatar
Level 2

@tykus Clearing config doesn't work. I'm using Xampp local server and I've also tried setting date.timezone="my locale" in the php.ini file. I'm testing with postman and I have a simple route just to return carbon::now(). If I return date('...') it gives me the correct time.

tykus's avatar

@Devio what is the value returned if you dd(config('app.timezone'))?

chiefguru's avatar

Hi @devio have you tried the obvious Carbon::now('my_timezone') e.g. Carbon::now('Australia\Melbourne')

We run operations in four countries and multiple time zones; our servers all run UTC and we change any time operations to use the local time zone.

Devio's avatar
Level 2

@chiefguru this still returns UTC time regardless of what timezone i put

tykus's avatar

@Devio ¯\_(ツ)_/¯

You are using Carbon\Carbon class from nesbot/carbon package, right? What version are you using?

Devio's avatar
Level 2

@tykus, @chiefguru After some more testing, I think Carbon isn't the issue, i.e.,

Route::get('test', function(){
$date = Carbon::now();
echo $date;
//Gives desired time zone date "2025-01-23 20:26:57"
return $date;
//Gives UTC date "2025-01-23T14:26:57.700959Z"
});

I think maybe its Laravel's middleware that's formatting the response?

Also what's is the difference between the two formats?

tykus's avatar

@Devio this is how a Carbon instance serializes itself. They have deprecated the serializedUsing method which allowed us to specify how it should be serialized, so now we need to format directly on the instance, e.g.

Route::get('test', function(){
    return Carbon::now()->toDateTimeString();
});

However, if you intend to use injest this Date into a Javascript application, you will be better to keep the ISO format that you current see.... Javascript understand what to do with this

https://kylekatarnls.medium.com/handle-dates-the-right-way-in-php-c215650fc4fa

Talinon's avatar
Talinon
Best Answer
Level 51

@devio This is the way Laravel returns the serialized date since version 7. You can read about it here:

https://laravel.com/docs/7.x/upgrade#date-serialization

Take special note within the documentation that states:

Please note that ISO-8601 dates are always expressed in UTC.

You can test this yourself by instead of just returning an object of Carbon, which will get serialized, you can return a string of your desired timezone:

return $date->toString();
tykus's avatar

@Talinon the OP is returning a Carbon instance directly; however, the information you provided is relating to Eloquent models. Laravel itself has nothing to do with the OP's issue, it is how Carbon itself is serialized.

Talinon's avatar

@tykus You are, of course, correct. But, the topic of how Carbon gets serialized is still the reason for the discrepancy.

Please or to participate in this conversation.