2

我正在为我的应用程序使用 symfony2。在日期类型表单字段验证期间,symfony 尝试解析传入的字符串日期值。由于某种原因,这在本地工作(运行 MAMP 和 php 5.3.6)但在我们的远程 Fedora 服务器上失败。(PHP 5.3.8)。这里有一些细节,我包括任何可能相关的东西。

实例化我正在使用的新 IntlDateFormatter 时

locale: en_US_POSIX
date format: 2
time format: -1
timezone: America/Chicago
calendar: 1
pattern: MM-dd-yyyy

使用像 11/21/2012 这样的日期在 IntlDateFormatter 上调用Parse

$timestamp = $this->getIntlDateFormatter()->parse($value);

这是 getIntl​​DateFormatter 方法。

protected function getIntlDateFormatter()
{
    $dateFormat = $this->dateFormat;
    $timeFormat = $this->timeFormat;
    $timezone = $this->outputTimezone;
    $calendar = $this->calendar;
    $pattern = $this->pattern;

    return new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
}

处理将字符串日期值转换为本地化日期时间值的整个类都在这里...

这会导致解析失败,可以使用以下方法访问错误:intl_get_error_message()

以下是远程机器上 phpinfo() 的一些片段:

国际配置

日期配置

如果它有帮助......整个phpinfo()的截图...... http://f.cl.ly/items/3q2q2C3Z0b0K1a0F0c3F/phpinfo%20.png

4

1 回答 1

3

我也遇到这个问题,然后我深入搜索,发现日期格式不对。你应该选择像这种格式的日期'format' => 'yyyy-MM-dd H:m'

所以这是完整的列表文件将此行添加到过滤器字段中

->add('createdAt', 'doctrine_orm_datetime_range', array('field_type' => 'sonata_type_datetime_range'), null, array(
   'widget' => 'single_text',
   'format' => 'yyyy-MM-dd H:m',
   'required' => false,
   'attr' =>array('class' => 'datetimepicker'))
  )

然后以这种格式输入开始日期和结束日期2014-09-29 4:46

希望这能解决问题

于 2014-09-29T11:17:27.707 回答