Laravel 集体日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44703523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Collective date format
提问by Norgul
Is there a way to set Laravel Collectivedate picker format to yyyy-mm-dd?
有没有办法将Laravel Collective日期选择器格式设置为yyyy-mm-dd?
I am using now:
我现在使用:
{{ Form::date('deadline', null,['class' => 'form-control']) }}
but in the front end I get an input field with mm/dd/yyyyinside. I tried parsing the Carboninstance as second parameter, but that does nothing.
但在前端,我得到了一个带mm/dd/yyyy内部的输入字段。我尝试将Carbon实例解析为第二个参数,但这没有任何作用。
{{ Form::date('deadline', \Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-control']) }}
回答by linktoahref
You could pass an DateTimeinstance for the second parameter. As per the source codeif the second parameter is an DateTime instance it would return the formatted date (Y-m-d).
您可以DateTime为第二个参数传递一个实例。根据源代码,如果第二个参数是 DateTime 实例,它将返回格式化的 date (Y-m-d)。
So you could try this,
所以你可以试试这个
{{ Form::date('deadline', new \DateTime(), ['class' => 'form-control']) }}
回答by wbail
No, Laravel Collective does not provide this option.
不,Laravel Collective 不提供此选项。
Use https://eonasdan.github.io/bootstrap-datetimepicker/
使用https://eonasdan.github.io/bootstrap-datetimepicker/
{{ Form::text('deadline', null, ['class' => 'form-control', 'id'=>'datetimepicker']) }}
Javascript
Javascript
$('#datetimepicker').datetimepicker({
format: 'yyyy-mm-dd'
});

