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

前端 未结 6 845
既然无缘
既然无缘 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:05

    Using a library as Laravel-Date you will just need to set the language of the app in the Laravel app config file and use its functions to format the date as you want.

    Set the language in /app/config/app.php

    'locale' => 'es',
    

    I've found this library pretty useful and clean. To use it, you can write something like the example in the library readme file. I leave the results in spanish.

    echo Date::now()->format('l j F Y H:i:s'); // domingo 28 abril 2013 21:58:16
    
    echo Date::parse('-1 day')->diffForHumans(); // 1 día atrás
    

    This is the link to the repository:

    https://github.com/jenssegers/laravel-date

    To install this library you can follow the instructions detailed in the following link:

    https://github.com/jenssegers/laravel-date#installation

提交回复
热议问题