gpt4 book ai didi

php - Laravel : Carbon shorten diffForHumans()

转载 作者:行者123 更新时间:2023-12-03 15:16:53 25 4
gpt4 key购买 nike

怎么修剪diffForHumans() ?

$post->created_at->diffForHumans()返回前一段时间 赞 3 days ago57 minutes ago , 或 2 hours ago .

怎样才能退货57 mins ago1W ago等等。

有什么办法吗?

Searched around but got nothing.

最佳答案

传递给 diffForHumans() 的第三个值用于缩短显示输出。

尝试类似的东西,

$post->created_at->diffForHumans(null, false, true)

在这里您可以看到 diffForHumans() 的注释及其接受的值。
     /**
* Get the difference in a human readable format in the current locale.
*
* When comparing a value in the past to default now:
* 1 hour ago
* 5 months ago
*
* When comparing a value in the future to default now:
* 1 hour from now
* 5 months from now
*
* When comparing a value in the past to another value:
* 1 hour before
* 5 months before
*
* When comparing a value in the future to another value:
* 1 hour after
* 5 months after
*
* @param Carbon|null $other
* @param bool $absolute removes time difference modifiers ago, after, etc
* @param bool $short displays short format of time units
* @param int $parts displays number of parts in the interval
*
* @return string
*/
public function diffForHumans($other = null, $absolute = false, $short = false, $parts = 1)
{

关于php - Laravel : Carbon shorten diffForHumans(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52371097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com