What's the best way to localise a date on Laravel?

前端 未结 6 843
既然无缘
既然无缘 2020-12-05 17:34

Take this example:

{{ $article->created_at->format(\'M\') }}

It returns Nov. I need to localise this to my language, so

6条回答
  •  清歌不尽
    2020-12-05 18:17

    It is also a good idea to set locale globally for each request (eg. in filters.php) when using Carbon date instances.

    App::before(function($request) {
        setlocale(LC_TIME, 'sk_SK.utf8');
    });
    

    and then proceed as usual

    $dt->formatLocalized('%b'); // $dt is carbon instance
    

    See format options here and list of locales here.

提交回复
热议问题