1

Good day to all, I want to make sure that the formatted date time is displayed in different language except for default English, say, in French. The code:

<small> {{$income->created_at->format('F jS, Y')}}</small>.

How is it possible to achieve?

Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
Mirasan
  • 259
  • 1
  • 4
  • 16

2 Answers2

2

Laravel uses Carbon under the hood for date operations. Carbon has several functions to localize datetime formats for different languages.

What you are looking for is isoFormat. This function expects the same parameters as php's own strftime function.

Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • hi dude, please can you help I have used {{$income->created_at->locale('fr_FR')->format('F jS, Y')}} but there happens error "Method Illuminate\Support\Carbon::locale does not exist. (View: C:\xampp\htdocs\TestingTask\resources\views\income\show.blade.php. I hope for your help – Mirasan Sep 07 '18 at 08:39
1

You can use locale method to set the localization in your app.

{{$income->created_at->locale('fr_FR')->format('F jS, Y')}}

For more information have a look on the API https://carbon.nesbot.com/docs/#api-localization

The ->locale() method only change the language for the current instance and has precedence over global settings.

You can also try

{{Carbon\Carbon::parse($income->created_at)->locale('fr_FR')->format('F jS, Y')}}
FULL STACK DEV
  • 15,207
  • 5
  • 46
  • 66