Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SYMFONY Form TimeType使用1970-01-01作为默认日期,在约束中设置的值大于或等于多少?_Php_Date_Symfony_Symfony Forms - Fatal编程技术网

Php SYMFONY Form TimeType使用1970-01-01作为默认日期,在约束中设置的值大于或等于多少?

Php SYMFONY Form TimeType使用1970-01-01作为默认日期,在约束中设置的值大于或等于多少?,php,date,symfony,symfony-forms,Php,Date,Symfony,Symfony Forms,我有一个符号形式的TimeType字段。在AbstractTypeextended类中,字段如下所示: $form->add('fieldTime', TimeType::class, array( 'label' => myLabel, 'constraints'=>array( new GreaterThanOrEqual(array('value'=>date('H:i'))),

我有一个符号形式的
TimeType
字段。在
AbstractType
extended类中,字段如下所示:

    $form->add('fieldTime', TimeType::class, array(
        'label' => myLabel,
        'constraints'=>array(
            new GreaterThanOrEqual(array('value'=>date('H:i'))),
            new Time()
        ),
    );
DateTime {#12481 ▼
  +"date": "1970-01-01 11:00:00.000000"
  +"timezone_type": 3
  +"timezone": "Europe/Paris"
}
问题是
date('H:i')
设置为约束中要比较的值
GreaterThanOrEqual
,拾取实际日期,如:
2016-02-14 10:15:00

Submit
上收到的值如下所示:

    $form->add('fieldTime', TimeType::class, array(
        'label' => myLabel,
        'constraints'=>array(
            new GreaterThanOrEqual(array('value'=>date('H:i'))),
            new Time()
        ),
    );
DateTime {#12481 ▼
  +"date": "1970-01-01 11:00:00.000000"
  +"timezone_type": 3
  +"timezone": "Europe/Paris"
}
如您所见,它具有用户选择的时间,但具有1970年的日期,因此约束始终为false

我想知道如何:

  • 使用 1970-01-01日期,但与实际时间一致
  • 或者如何使用默认的今天日期和用户通过表单提交的时间
您可以使用
new DateTime()
获取完整的日期,而不仅仅是一天中的时间:

$form->add('fieldTime', TimeType::class, array(
    'label' => myLabel,
    'constraints'=>array(
        new GreaterThanOrEqual("today")
    ),
    'data' => new DateTime(),
);

请注意,“今天”使用服务器配置的时区。如果要指定它,请将其附加到日期字符串,即“今天UTC”

我已经尝试将“今天”作为约束中的值,它与日期('H:i')@nyluje the
new DateTime()相同
应该是您需要的。您的意思是通过设置今天的日期而不是1970-01-01来更改提交前事件中提交的时间吗?我尝试传递'data'=>new DateTime(),但当它被提交时,它会将日期更改为1970-01-01