@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, @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?
@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.
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
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:
@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.