PHP Carbon take number of minutes & convert to days

时光毁灭记忆、已成空白 提交于 2019-12-31 04:01:08

问题


I am trying to convert a number on minutes into number of days using Carbon.

$minutes = 1400;

I want to do something like below (which of course, does not work):

Carbon->minutes($minutes)->days();

I cannot find an example of this. Thanks for any help.


回答1:


Not tested, but a quick look at the docs suggests it might be aimed more at DateTime objects than differences in time, so you could do something like this:

$now  = Carbon::now();
$days = $now->diffInDays($now->copy()->addMinutes($minutes));



回答2:


Maybe CarbonInterval::minutes($minutes)->cascade();?

Will cascade down your value and format it for humans.



来源:https://stackoverflow.com/questions/36684969/php-carbon-take-number-of-minutes-convert-to-days

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!