gpt4 book ai didi

php - laravel - 碳 | diffForHumans() 较短版本?

转载 作者:行者123 更新时间:2023-12-01 22:20:34 24 4
gpt4 key购买 nike

我正在尝试找出如何缩短 laravel 中 Carbon 库提供的 diffForHumans 方法的输出。

diffForHumans 的默认格式如下所示:(来自文档)

  • 将过去的值与现在的默认值进行比较时:

    1. 5个月前

    2. 1小时前

但我希望输出类似于:

  1. 1小时
  2. 5 分钟
  3. 5个月
  4. 2 年
  5. 现在

我怎样才能实现这个目标?

最佳答案

根据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

关于php - laravel - 碳 | diffForHumans() 较短版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732002/

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