我正在尝试在我的项目中实现评论部分,并希望显示评论发布的时间。
所以我做了:
{{ $comment->created_at->diffForHumans() }}
输出是
3 hours from now
但我想要的输出是
3 hours ago
我错过了什么吗?我在 Laravel 中这样做
最佳答案
您可以使用此 $comment->created_at->diffForHumans(null, true)
删除 ago,from now, etc
然后您可以自己附加前。所以你最终会得到:
$comment->created_at->diffForHumans(null, true).' ago'
(NB: you may need to check why this does not work by default)
关于php - 如何更改 Carbon 的 diffForHumans 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51099331/