我目前正在尝试用datetimepicker添加一个表单字段,因为我正在提交,我得到了以下错误
This value is not valid. pesagem1
Symfony'Component'Validator'ConstraintViolation
Object(Symfony'Component'Form'Form).children[pesagem1] = 27/04/2016 23:59
Caused by:
Symfony'Component'Form'Exception'TransformationFailedException
Unable to reverse value for property path "pesagem1": DateTime::__construct(): Failed to parse time string (27/04/2016 23:59) at position 0 (2): Unexpected character
Caused by:
Symfony'Component'Form'Exception'TransformationFailedException
DateTime::__construct(): Failed to parse time string (27/04/2016 23:59) at position 0 (2): Unexpected character
Caused by:
Exception
DateTime::__construct(): Failed to parse time string (27/04/2016 23:59) at position 0 (2): Unexpected character
这是我的实体+表单
//实体
/** @ORM'Column(type="datetime") */
private $pesagem1;
//形式
->add('pesagem1','datetime', array(
'widget' => "single_text",
'html5' => false,
'date_format'=>"dd/MM/yyyy hh:mm",
'attr'=>array(
'class'=>'datetimepickz form-control',
'style' => 'width: 70%',
'data-format'=>"dd/MM/yyyy hh:mm"
)
)
)
js+树枝
$('.datetimepickz').datetimepicker({
locale: moment.locale('pt')
});
<div class="form-group">
<label>Primeira Pesagem</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envira"></i></span>
{{ form_widget(form.pesagem1) }}
</div>
<div>
{{ form_errors(form.pesagem1) }}
</div>
</div>
根据symfony2探查器,类似字符串的接缝是"正确的",已经尝试使用日期格式dd/mm/yyy hh:mm,d/m/Y hh:mm。并且都返回相同的问题。
如有任何帮助或提示,我们将不胜感激。ty
阅读后,我应该使用字段';日期时间';或者';时间戳';?
我更改了日期格式,现在一切都很好。
$('.datetimepickz').datetimepicker({
locale: moment.locale('pt'),
format: 'YYYY-MM-DD HH:mm'
});