In Laravel 5.4, in .env
I have:
APP_LOCALE=es
APP_FALLBACK_LOCALE=en
APP_LOCALE_PHP=es_US
and in config/app.php
:
I suggest you to use Carbon, that provides handy primitives for DateTime operations and it is fully supported by Laravel out of the box (so no additional packages or composer require
actions). To format a localized date you need just few lines of code:
use \Carbon\Carbon;
...
setlocale(LC_TIME, 'es_ES.UTF-8');
Carbon::setLocale('es');
$mydate = Carbon::parse($data->created)->formatLocalized('%d %B %Y');
If you want to skip the Carbon
steps just setting the time locale with setlocale
will work out of the box. To get the list of installed locales in your UNIX machine run the command
$ locale -a
in your terminal or if you need to add a locale to your machine uncomment the line corresponding to you locale in /etc/locale.gen
(e.g. es_ES.UTF8
) then run the the following command in your terminal to generate the locale
$ sudo locale-gen es_ES.UTF-8
then update the locale list in your machine typing
$ sudo update-locale
hope it helps.