Laravel 5.5 - change date format using jenssegers/date package


Hi Friends,

In this article i will let you know how to change date format using jenssegers/date composer package in Laravel 5.5. jenssegers/date package provide us Date facade. Date facade through we can simply change date formate, calculate difference between two dates its.

jenssegers/date package provide amazing feature is multi-language support. If you want to display your date in specific language then they are support almost languages as listed here : Albanian, Arabic, Azerbaijani, Bangla, Basque, Brazilian Portuguese, Bulgarian, Catalan, Croatian, Chinese Simplified, Chinese Traditional, Czech, Danish, Dutch, English, Esperanto, Estonian, Finnish, French, Galician, Georgian, German, Greek, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Italian, Japanese, Kazakh, Korean, Latvian, Lithuanian, Macedonian, Malay, Norwegian, Polish, Portuguese, Persian (Farsi), Romanian, Russian, Thai, Serbian (latin), Serbian (cyrillic), Slovak, lovenian, Spanish, Swedish, Turkish, Turkmen, Ukrainian, Vietnamese, Welsh.

You can simply use this plugin and it's amazing. So you have to just follow bellow example.

Install Package:

now we have to install jenssegers/date composer package for date facade. So simply run bellow composer command for install package.

composer require jenssegers/date

After install successfully above jenssegers/date package we need to add into providers and aliases array of configuration file. So let's add following way:

config/app.php

<?php

return [

....

'providers' => [

....

'Jenssegers\Date\DateServiceProvider',

],

'aliases' => [

....

'Date' => Jenssegers\Date\Date::class,

]

Simple Example of Language Support:

Route::get('date-formate', function () {


\Date::setLocale('hi');

$date = Date::now()->format('l j F Y H:i:s');


dd($date);

});

Change Date Format:

Route::get('date-formate', function () {


\Date::setLocale('hi');

$date = Date::parse('2015-02-01 01:01:10')->format('l j F Y');


dd($date);

});

Output:

"रविवार 1 फरवरी 2015"

You can also see more details about jenssegers/date package from here Click Here.

I hope you found your best solution...






November 8, 2017 | Category : PHP Laravel Laravel 5 Laravel 5.5
Related Posts