Php 我怎样才能在laravel上得到含碳的生日(年、月、日)?
我想将出生日期转换为laravel 5.4上带有碳元素的年、月、日格式 根据碳纤维公司的文件,获得叶片寿命的方法如下Php 我怎样才能在laravel上得到含碳的生日(年、月、日)?,php,laravel,php-carbon,Php,Laravel,Php Carbon,我想将出生日期转换为laravel 5.4上带有碳元素的年、月、日格式 根据碳纤维公司的文件,获得叶片寿命的方法如下 Carbon\Carbon::parse($bday)->age 但是结果是“0”,我想要这个 $bday = '2017-10-01' = 0 year 1 month 4 days 谢谢你,对不起,我的英语。碳的年龄只返回一个人年龄的年数,如你所见 在您的模型中,您可以设置一个getAge方法,该方法将以年、月和日为单位返回年龄: public function
Carbon\Carbon::parse($bday)->age
但是结果是“0”,我想要这个
$bday = '2017-10-01' = 0 year 1 month 4 days
谢谢你,对不起,我的英语。碳的
年龄
只返回一个人年龄的年数,如你所见
在您的模型中,您可以设置一个getAge
方法,该方法将以年、月和日为单位返回年龄:
public function getAge(){
return $this->birthdate->diff(Carbon::now())
->format('%y years, %m months and %d days');
}
您可以在视图中将您的模型调用为
$user->getAge()
Carbon的age
只返回一个人年龄的年数,如您所见
在您的模型中,您可以设置一个getAge
方法,该方法将以年、月和日为单位返回年龄:
public function getAge(){
return $this->birthdate->diff(Carbon::now())
->format('%y years, %m months and %d days');
}
您可以在视图中将您的模型称为$user->getAge()