如何更改 Carbon 的 diffForHumans 格式

Kur*_*ate 4 php laravel php-carbon

我正在尝试在我的项目中实施评论部分,并希望显示评论发布的时间。

所以我做了:

 {{ $comment->created_at->diffForHumans() }}
Run Code Online (Sandbox Code Playgroud)

输出是

  3 hours from now 
Run Code Online (Sandbox Code Playgroud)

但我想要的输出是

3 hours ago 
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我在 Laravel 中这样做

Olu*_*kin 13

您可以使用, this$comment->created_at->diffForHumans(null, true)来删除ago,from now, etc然后您可以自己附加前。所以你最终会得到:

$comment->created_at->diffForHumans(null, true).' ago'
Run Code Online (Sandbox Code Playgroud)

(注意:您可能需要检查为什么默认情况下这不起作用)

参考:https : //carbon.nesbot.com/docs/#api-humandiff