Laravel 集体日期格式
Laravel Collective date format
有没有办法将 Laravel Collective
日期选择器格式设置为 yyyy-mm-dd
?
我现在在用:
{{ Form::date('deadline', null,['class' => 'form-control']) }}
但在前端我得到一个输入字段,里面有 mm/dd/yyyy
。我尝试将 Carbon
实例解析为第二个参数,但这没有任何作用。
{{ Form::date('deadline', \Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-control']) }}
否,Laravel Collective 不提供此选项。
使用https://eonasdan.github.io/bootstrap-datetimepicker/
{{ Form::text('deadline', null, ['class' => 'form-control', 'id'=>'datetimepicker']) }}
Javascript
$('#datetimepicker').datetimepicker({
format: 'yyyy-mm-dd'
});
您可以为第二个参数传递一个 DateTime
实例。根据 source code 如果第二个参数是 DateTime 实例,它将 return 格式化日期 (Y-m-d)
.
所以你可以试试这个,
{{ Form::date('deadline', new \DateTime(), ['class' => 'form-control']) }}
有没有办法将 Laravel Collective
日期选择器格式设置为 yyyy-mm-dd
?
我现在在用:
{{ Form::date('deadline', null,['class' => 'form-control']) }}
但在前端我得到一个输入字段,里面有 mm/dd/yyyy
。我尝试将 Carbon
实例解析为第二个参数,但这没有任何作用。
{{ Form::date('deadline', \Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-control']) }}
否,Laravel Collective 不提供此选项。
使用https://eonasdan.github.io/bootstrap-datetimepicker/
{{ Form::text('deadline', null, ['class' => 'form-control', 'id'=>'datetimepicker']) }}
Javascript
$('#datetimepicker').datetimepicker({
format: 'yyyy-mm-dd'
});
您可以为第二个参数传递一个 DateTime
实例。根据 source code 如果第二个参数是 DateTime 实例,它将 return 格式化日期 (Y-m-d)
.
所以你可以试试这个,
{{ Form::date('deadline', new \DateTime(), ['class' => 'form-control']) }}