Symfony2 datetime字段形式 [英] Symfony2 datetime field form

查看:89
本文介绍了Symfony2 datetime字段形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Symfony2应用程序,它以一种形式接收JSON数据。其中一个领域是日期时间。如果我以这种方式渲染字段表单:

   - > add('startDate','date',array b $ b'widget'=>'single_text',
'format'=>'yyyy-MM-dd HH:mm:ss'))
pre>

这样做可以接受:

 startDate 2015-05-03 12:30:00

但是我需要以这种方式引入一个datetime :

 startDate:2015-05-12T15:43:00 + 0200

如何在字段中设置此格式?

解决方案

http://php.net/manual/en/function。 date.php



c=> ISO 8601日期(PHP 5中添加) => 2004-02-12T15 :19:21 + 00:00



尝试这样:

  - > add('startDate','date',array(
'widget'=>'single_text',
'format'=>'c'))

我希望它有帮助。 b $ b

I have a Symfony2 application which receive a JSON data in a form. One of the field is a date time. If I renderize the field form in this way:

->add('startDate', 'date', array(
        'widget' => 'single_text',
        'format' => 'yyyy-MM-dd HH:mm:ss'))

This accept something like:

"startDate": "2015-05-03 12:30:00"

But I need to introduce a datetime in this way:

"startDate": "2015-05-12T15:43:00+0200"

How can I set this format in the field?

解决方案

On http://php.net/manual/en/function.date.php

"c" => ISO 8601 date (added in PHP 5) => 2004-02-12T15:19:21+00:00

Try this:

->add('startDate', 'date', array(
    'widget' => 'single_text',
    'format' => 'c'))

I hope it helps.

这篇关于Symfony2 datetime字段形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆