Php laravel-碳| diffForHumans()较短版本?
我试图找出如何缩短laravel中碳库提供的Php laravel-碳| diffForHumans()较短版本?,php,laravel,date,laravel-5.4,php-carbon,Php,Laravel,Date,Laravel 5.4,Php Carbon,我试图找出如何缩短laravel中碳库提供的diffForHumans方法的输出 diffForHumans的默认格式如下:(来自文档) 将过去的值与现在的默认值进行比较时: 5个月前 一小时前 但我希望输出类似于: 1小时 5分钟 5个月 两年 刚才 如何实现这一点?根据diffForHumans /** * Get the difference in a human readable format in the current locale. * * * @param Carb
diffForHumans
方法的输出
diffForHumans的默认格式如下:(来自文档)
- 将过去的值与现在的默认值进行比较时:
- 5个月前
- 一小时前
如何实现这一点?根据
diffForHumans
/**
* Get the difference in a human readable format in the current locale.
*
*
* @param Carbon|null $other
* @param bool $absolute removes time difference modifiers ago, after, etc
* @param bool $short displays short format of time units
*
* @return string
*/
public function diffForHumans(Carbon $other = null, $absolute = false, $short = false) {
...
}
要删除修饰符,请将第二个参数传递为true
,并将第三个参数传递为true
源代码位于
vendor/nesbot/carbon/src/Carbon/Carbon.php
碳元素让你可以选择去除“ago” $time=\Carbon\Carbon::now()->subMinutes(1)->diffForHumans(null,true) 如果您需要使用“1小时5分钟”,只需
str_替换(['hours'、'minutes']、['h'、'mins']、$time)
对于刚才
,您需要指定刚才
的长度