Laravel 9 - Change Date Format using Jenssegers/Date Package


Share:
 | Published By: Admin | Published On: Apr 16, 2022 | Category: Laravel 9

Hi Friends,

This simple article demonstrates of laravel 9 change date format using jenssegers/date package. This article goes in detailed on date multiple language. step by step explain how to create in multiple language laravel 9. you can understand a concept of change date formate.

In this article i will let you know how to change date format using jenssegers/date composer package in Laravel 9. 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 etc.

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

First of all you need required jenssegers/date package install.

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Step 2: 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:

Step 3: Add Provider config/app.php
<?php

return [
    'providers' => [
        Jenssegers\Date\DateServiceProvider::class,
    ],
    'aliases' => [
        'Date' => Jenssegers\Date\Date::class,
    ]
Step 4: Create Routes routes/web.php
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('date-formate', function () {
    \Date::setLocale('hi');
    $date = Date::now()->format('l j F Y H:i:s');

    dd($date);
});
routes/web.php
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('date-formate', function () {
    \Date::setLocale('nl');
    $date = Date::parse('2021-12-12 01:01:10')->format('l j F Y');

    dd($date);
});

I hope you found your best solution...

Share: