Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the date language in laravel?

I want to change the language of the date i get in my view from english to french

{{ strftime("%d %B %Y, %H:%M", strtotime($article->created_at)) }}
like image 550
Youssef Boudaya Avatar asked Sep 10 '25 07:09

Youssef Boudaya


2 Answers

we can use another method with translatedFormat

    Carbon::setLocale('fr');
echo $base_weight_category->created_at->translatedFormat('l jS F Y');

we can see result jeudi 2 avril 2020

like image 118
Berthold Feujo Avatar answered Sep 13 '25 13:09

Berthold Feujo


Set Carbon locale first, then access

Carbon::setLocale('fr');
$date_to_show_in_view = $article->created_at->diffForHumans();

For your second query(to get 15 Mars 2018), use this-

<?php
   setlocale(LC_TIME, 'French');
   echo $base_weight_category->created_at->formatLocalized('%d %B %Y');
?>
like image 37
Sohel0415 Avatar answered Sep 13 '25 13:09

Sohel0415