gpt4 book ai didi

laravel - Carbon diffForHumans 不能在 laravel 5.5 中使用吗?

转载 作者:行者123 更新时间:2023-12-02 02:55:38 26 4
gpt4 key购买 nike

首先我使用 Carbon\Carbon;然后我尝试回应 doc 的 difforhumans 引用:https://carbon.nesbot.com/docs/#api-humandiff

echo Carbon::parse('2019-08-03')->diffForHumans('2019-08-13');

laravel 5.5 说 Parse error: syntax error,

更新

我安装了 laravel 5.6 但我降级到 5.5

这是我的完整代码

use Carbon\Carbon;
public function index(Request $request)
{
dd(\Carbon\Carbon::parse('2019-08-03')->diffForHumans('2019-08-13'));

}

enter image description here

最佳答案

首先 diffForHumans 不要接受任何参数。如果只是从 diffForHumans 中删除日期将不起作用..

试试这个:

use Carbon\Carbon;
public function index(Request $request)
{
dd(Carbon::createFromFormat('Y-m-d','2019-08-03')->diffForHumans());

}

关于laravel - Carbon diffForHumans 不能在 laravel 5.5 中使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49626111/

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