我想把生日转换成年份、月、日的格式,在laravel 5.4上写上碳。
根据碳的资料,在刀片上计算年龄的方法是这样的
Carbon\Carbon::parse($bday)->age
但结果是'0‘我想要这个
$bday = '2017-10-01' = 0 year 1 month 4 days
谢谢,对不起我的英语。
发布于 2017-11-05 07:19:43
正如你所见,碳的age
只返回一个人年龄的年数。
在您的模型中,您可以设置一个getAge
方法,该方法将在几年、几个月和几天内返回年龄:
public function getAge(){
return $this->birthdate->diff(Carbon::now())
->format('%y years, %m months and %d days');
}
您可以将视图中的模型称为$user->getAge()
。
https://stackoverflow.com/questions/47118910
复制相似问题