I want to change date format in english language("Monday, 04 July 2020") to indonesia(Senin, 04 Juli 2020). I change config/App.php
'locale' => 'id',
and add some code to Providers/AppServiceProvider.php
public function boot()
{
config(['app.locale' => 'id']);
Carbon::setLocale('id');
date_default_timezone_set('Asia/Jakarta');
}
my model
public function dateFormat()
{
return \Carbon\Carbon::parse($this->attributes['tanggal_acara'])
->formatLocalized("%A, %d %B %Y");
}
and this my blade
{{ $event->dateFormat() }}
but the result still same "Monday, 04 July 2020"
anyone tell me what I've missed?
Set the language in /app/config/app.php
'timezone' => 'Asia/Jakarta',
'locale' => 'id',
'faker_locale' => 'id_ID',
// App\Providers\AppServiceProvider
public function boot()
{
config(['app.locale' => 'id']);
Carbon::setLocale('id');
date_default_timezone_set('Asia/Jakarta');
}
Because you are using formatLocalized()
, You will need to call php's setlocale()
like so
public function boot()
{
setlocale(LC_TIME, 'id_ID');
config(['app.locale' => 'id']);
Carbon::setLocale('id');
date_default_timezone_set('Asia/Jakarta');
}
Also as per Sammitch's comment, you need to make sure the locale is configured on your server (on linux this can be checked using locale -a
command in the console) as setlocale()
will not work otherwise
solved use this liblary https://github.com/jenssegers/date
This date library extends Carbon with multi-language support. Methods such as format, diffForHumans, parse, createFromFormat and the new timespan, will now be translated based on your locale.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.