I clarify that although I am in a PHP environment with Eloquent-ORM and using Carbon to handle dates on the server side, I am NOT using Laravel. I want to show a date in Spanish using Carbon, but I can't get it to show in that language, I have this:
use Carbon\Carbon;
Carbon::setLocale("es");
$fechaCarbon = Carbon::parse($miEgreso->created_at)->toDayDateTimeString();
I have also tried:
$fechaCarbon = Carbon::parse($miEgreso->created_at)->locale("es")->toDayDateTimeString();
In both cases I get something like:
"Mon, Jan 4, 2021 4:53 PM"
When I expect to get:
"Mon, Jan 4, 2021 4:53 PM"
Or something similar where it is interpreted that the expression is in Spanish.
Carbon doesn't seem to have localization support for many of its native features, so you have to do a bit of work around translations. In this case using isoFormat is a way out. For example, if you use:
now()->locale('es-ES')->isoFormat('ddd ,MMM D, YYYY h:mm a');
Which would come to the same thing if you use:
now()->locale('es-ES')->isoFormat('llll');
You will get as output:
"lun. ,jun. 21, 2021 5:03 p. m."