在 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:34Aujourd’hui à 12:40*/echo $notificationForJohn;/*Jun 15, 2018 12:34 PMToday at 12:40 PM*/
使用此存储库 : 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 localeecho Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16echo 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');