[英]Laravel / Carbon - Return diffForHumans() in the shorter format like instagram
[英]laravel - Carbon | diffForHumans() shorter version?
我試圖弄清楚如何縮短diffForHumans
中Carbon庫提供的diffForHumans
方法的輸出。
diffForHumans
的默認格式是這樣的:( 來自文檔 )
將過去的值與現在的默認值進行比較時:
5個月前
1小時前
但我希望輸出是這樣的:
我該如何實現?
按照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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.