我想要在laravel 5中获得当前的时间戳,我已经这样做了-
$current_time = Carbon\Carbon::now()->toDateTimeString();
我搞错了--“找不到碳”-
我能做什么?
有人能帮帮忙吗?
发布于 2015-09-22 22:49:41
如果您想要日期时间字符串,可以尝试这样做:
use Carbon\Carbon;
$current_date_time = Carbon::now()->toDateTimeString(); // Produces something like "2019-03-11 12:25:00"
如果你想要时间戳,你可以尝试:
use Carbon\Carbon;
$current_timestamp = Carbon::now()->timestamp; // Produces something like 1552296328
发布于 2018-06-05 16:09:39
对于Laravel 5.5或更高版本,只需使用内置帮助器
$timestamp = now();
如果你想要一个unix时间戳,你也可以尝试这样做:
$unix_timestamp = now()->timestamp;
发布于 2015-09-22 22:46:35
您需要在carbon类之前添加另一个\
,以便在根命名空间中启动。
$current_time = \Carbon\Carbon::now()->toDateTimeString();
另外,要确保你的composer.json
中有碳元素。
https://stackoverflow.com/questions/32719972
复制相似问题