Php Symfony2和DateTimePicker的日期格式是否错误?
我正在尝试使用symfony表单选择日期时间。 这是我的表格:Php Symfony2和DateTimePicker的日期格式是否错误?,php,jquery,mysql,symfony,datepicker,Php,Jquery,Mysql,Symfony,Datepicker,我正在尝试使用symfony表单选择日期时间。 这是我的表格: /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('formation_date','datetime',array('label
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('formation_date','datetime',array('label' => "Séance le :",
'widget' => 'single_text',
'format' => 'dd/MM/yyyy hh:mm',
'attr' => array('class' => 'date', 'readonly' => 'readonly')
))
;
}
我使用的是jquery日期时间选择器。
这是我在页面上调整数据的脚本:
<script type="text/javascript">
$(document).ready(function() {
$.datepicker.setDefaults(
$.extend(
{'dateFormat':'dd/mm/yy'},
$.datepicker.regional['fr']
)
);
$.timepicker.setDefaults(
$.extend(
{'timeFormat':'hh:mm:00'}
)
);
jQuery('.date').datetimepicker({
changeYear: true,
showButtonPanel: true,
monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
dayNamesShort: ['Dim.','Lun.','Mar.','Mer.','Jeu.','Ven.','Sam.'],
dayNamesMin: ['D','L','M','M','J','V','S'],
currentText: 'Aujourd\'hui',
closeText: 'Fermer',
prevText: 'Précédent',
nextText: 'Suivant',
minDate: "y",
maxDate: "+10y"
});
});
</script>
我有
DateTime::_构造():无法分析位置0(2)处的时间字符串(2014年6月21日12:00:00):意外字符
如果我尝试这样做:
$date = new DateTime($request->request->get('intranet_rhbundle_dateformation')["formation_date"]);
因此,我不知道如何解决它…对于
无法解析时间字符串的问题,请尝试以下操作:
$date = new DateTime::createFromFormat(
'd/m/Y H:i:s',
$request->request->get('intranet_rhbundle_dateformation')["formation_date"]
);
表格上不应该是“格式”=>“d/m/Y H:i”
?不,如果我这样说,我有:“format”选项应该包含字母“y”、“M”和“d”。它的当前值是“d/M/y H:I”。^^^ formation\u date是我的实体中的一个DateTime字段:/*****@var string$formation\u date**@ORM\Column(name=“formation\u date”,type=“DateTime”,nullable=false)*@Assert\DateTime()***/私人$成立日期;不需要“新的”。根据你的建议,我有:object(DateTime)[779]public'date'=>string'2014-06-19 12:00:00'(length=19)public'timezone\u type'=>int3 public'timezone'=>string'UTC'(length=3),这是个好消息:)我尝试了这个日期,希望它能起作用。你能var\u dump($request->->request->->get('intranet\u rhbundle\u dateformation')[“formation_date”])
?在编辑之前,我尝试了你糟糕的日期格式,在发布我的评论后,我看到了明显的错误。对不起!是的,最后的方法不是很干净,但它正在工作!我希望任何人都能找到正确的配置,不需要使用日期时间变量。你的答案是正确的,谢谢!)
$date = new DateTime::createFromFormat(
'd/m/Y H:i:s',
$request->request->get('intranet_rhbundle_dateformation')["formation_date"]
);