【发布时间】:2018-11-09 16:23:54
【问题描述】:
我需要将 30 天转换为 1 个月。如果月份和天数是平均值,那么就像 1 年 2 个月 2 天 我在下面尝试过,但它会返回错误的结果
echo CarbonInterval::days(30)->cascade()->forHumans();
谁能帮我实现这个目标?
我尝试了以下解决方案,但只有 2 天的差异
$convert = '30'; // days you want to convert
$years = ($convert / 365) ; // days / 365 days
$years = floor($years); // Remove all decimals
$month = ($convert % 365) / 30.5; // I choose 30.5 for Month (30,31) ;)
$month = floor($month); // Remove all decimals
$days = ($convert % 365) % 30.5; // the rest of days
// Echo all information set
echo 'DAYS RECEIVE : '.$convert.' days<br>';
echo $years.' years - '.$month.' month - '.$days.' days';
有没有使用碳的好方法
【问题讨论】:
标签: php laravel laravel-5 php-carbon