Laravel和碳返回不正确的时间
问题描述:
我填充在我的控制器使用这个日期时间,本地输入字段:Laravel和碳返回不正确的时间
public function create()
{
$task = new Task();
$task->start_date = Carbon::now();
$task->due_date = Carbon::now();
return view('tasks.create', compact('task'));
}
,这在我看来:
{!! Form::input('datetime-local', 'start_date', $task->start_date->format('Y-m-d\TH:m'), ['class' => 'form-control']) !!}
{!! Form::input('datetime-local', 'due_date', $task->due_date->format('Y-m-d\TH:m'), ['class' => 'form-control']) !!}
然而,字段的值总是:
<input class="form-control" name="start_date" type="datetime-local" value="2016-05-12T22:05" id="start_date">
如果我在create()
方法做一个dd($task)
属性有当前时间英寸
#attributes: array:2 [▼
"start_date" => Carbon {#186 ▼
+"date": "2016-05-12 22:20:14.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"due_date" => Carbon {#187 ▼
+"date": "2016-05-12 22:20:14.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
]
试图找出为什么输入显示不正确的时间,当属性具有正确的时间值。
答
您的格式是:
Y-m-d\TH:m
这意味着:
(Year to 4 digits)-(Month with Leading zeros)-(Day to 2 digits with leading zeros)T(Hours in 24 hour format):(Month with Leading zeros)
你想:
Y-m-d\TH:i // 'i' = minutes with leading zeros
感谢您的建议,我不能相信我错过了!只是为了纠正你(对不起)'j'是一个月的日子'我'是分钟。如果你编辑你的答案,我会将其标记为正确的。再次感谢! – showFocus
是的!谢谢!在你回答之前,我发现了这一点。它是固定的。 – tptcat