如何更改 Carbon 的 diffForHumans 格式

How to change Carbon's diffForHumans Formatting

我正在尝试在我的项目中实现一个评论部分,并想显示评论是在多长时间前发布的。

所以我做到了:

 {{ $comment->created_at->diffForHumans() }}

输出是

  3 hours from now 

但我想要的输出是

3 hours ago 

我错过了什么吗?我在 laravel

中这样做

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

$comment->created_at->diffForHumans(null, true).' ago'

(NB: you may need to check why this does not work by default)

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

diffForHumans("null",真,真); 你需要像这样通过所以你最终会得到

1 小时前 = 1 小时 25 分钟前 = 25 米