我的代码如下:
$value = \Carbon\Carbon::createFromFormat('Y-m-d', $value)->format('m/d/Y');
和函数格式返回字符串,我想设置格式但返回Carbon对象,如:
$value = \Carbon\Carbon::createFromFormat('Y-m-d', $value)->formatReturnObject('m/d/Y');
答案 0 :(得分:0)
我很快找到了解决方案:
$birthday= \Carbon\Carbon::createFromFormat('Y-m-d', $birthday);
$birthday->setToStringFormat('m/d/Y');
return $birthday;
如果我这样做:
echo $birthday;
print_r($birthday);
输出是:
06/17/1988
Carbon\Carbon Object
(
[date] => 1988-06-17 07:55:58.000000
[timezone_type] => 3
[timezone] => UTC
)