2 回答

TA貢獻1757條經驗 獲得超7個贊
在 laravel 中,您可以使用 Carbon 來管理應用程序中的日期或時間。查看此 https://carbon.nesbot.com/docs/
在碳中,您可以使用簡單的代碼格式化日期。碳文檔中的示例
// Let say Martin from Paris and John from Chicago play chess
$martinDateFactory = new Factory([
'locale' => 'fr_FR',
'timezone' => 'Europe/Paris',
]);
$johnDateFactory = new Factory([
'locale' => 'en_US',
'timezone' => 'America/Chicago',
]);
// Each one will see date in his own language and timezone
// When Martin moves, we display things in French, but we notify John in English:
$gameStart = Carbon::parse('2018-06-15 12:34:00', 'UTC');
$move = Carbon::now('UTC');
$toDisplay = $martinDateFactory->make($gameStart)->isoFormat('lll')."\n".
$martinDateFactory->make($move)->calendar()."\n";
$notificationForJohn = $johnDateFactory->make($gameStart)->isoFormat('lll')."\n".
$johnDateFactory->make($move)->calendar()."\n";
echo $toDisplay;
/*
15 juin 2018 12:34
Aujourd’hui à 12:40
*/
echo $notificationForJohn;
/*
Jun 15, 2018 12:34 PM
Today at 12:40 PM
*/

TA貢獻1946條經驗 獲得超3個贊
使用此存儲庫 : https://github.com/jenssegers/laravel-date
要安裝此庫,您可以按照以下說明操作:https://github.com/jenssegers/laravel-date#installation
使用庫作為Laravel-Date,您只需要在Laravel應用程序配置文件中設置應用程序的語言,并使用其函數根據需要格式化日期。
在 /app/config/app 中設置語言.php
'locale' => 'fr',
例子:
use Jenssegers\Date\Date;
Date::setLocale('nl'); //Change this to your preferred locale
echo Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16
echo Date::parse('-1 day')->diffForHumans(); // 1 dag gelede
印地語示例:
Date::setLocale('hi');
echo Date::now()->format('l j F Y H:i:s');
法語示例:
Date::setLocale('fr');
echo Date::now()->format('l j F Y H:i:s');
- 2 回答
- 0 關注
- 114 瀏覽
添加回答
舉報