Symfony 日期时间字段格式 [英] Symfony datetime field format
问题描述
我有一个表单中的日期时间字段,我想为其提供格式掩码 yyyy-mm-dd hh:mi
,我使用以下代码:
I have a datetime field in a form which I want to give format mask yyyy-mm-dd hh:mi
, and I use the following code:
$builder->add('beginDate', 'datetime', array('widget' => 'single_text',
'date_format' => 'yyyy-MM-dd HH:i'))
但是我在表单字段中得到的是这样的:
But what I get in form field is something like this:
2014-08-25T22:37:37Z
2014-08-25T22:37:37Z
我想要类似的东西:
2014-08-25 22:37
2014-08-25 22:37
我能得到这个吗?
我看过这个和this 但没有找到一个真实的例子小时(24 小时制)和分钟
I've seen this and this but didn't find a real example for hours (24 hour format) and minutes
谢谢
推荐答案
你应该使用 格式选项,它接受HTML5 DateTime 格式.
You should use the format option which accepts HTML5 DateTime format.
$builder->add(
'beginDate',
'datetime',
array(
'widget' => 'single_text',
'format' => 'yyyy-MM-dd HH:mm'
)
)
当使用 widget = single_text
时,应该使用 format
选项而不是 date_format
.
The format
option should be used instead of date_format
when using widget = single_text
.
这篇关于Symfony 日期时间字段格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!