[英]Format date string in carbon in laravel5?
I want to convert $date='01-07-2010'
in to 2010-07-01
我想将
$date='01-07-2010'
转换为2010-07-01
My following code is not wokring, 我的以下代码无法唤醒,
Carbon::createFromFormat('Y-m-d', $date);
It throws error, 它引发错误,
InvalidArgumentException in Carbon.php line 414: Trailing data
How can I solve this? 我该如何解决?
If your date format is dmY
then 如果您的日期格式为
dmY
则
Carbon::createFromFormat('Y-m-d', $date);
won't work, because you're not specifying the correct format; 无法使用,因为您没有指定正确的格式; you need
你需要
Carbon::createFromFormat('d-m-Y', $date);
The format that you specify as the date-format for your value must match the actual format of the date string that you want to convert to a Carbon object 您指定为值的日期格式的格式必须与要转换为Carbon对象的日期字符串的实际格式匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.