看那DateType類的代碼,它有一個格式選項:
$allowedFormatOptionValues = array(
\IntlDateFormatter::FULL,
\IntlDateFormatter::LONG,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::SHORT,
);
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
if (!in_array($format, $allowedFormatOptionValues, true)) {
if (is_string($format)) {
$defaultOptions = $this->getDefaultOptions($options);
$format = $defaultOptions['format'];
$pattern = $options['format'];
} else {
throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
}
}
$formatter = new \IntlDateFormatter(
\Locale::getDefault(),
$format,
\IntlDateFormatter::NONE,
\DateTimeZone::UTC,
\IntlDateFormatter::GREGORIAN,
$pattern
);
UPDAT E
$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MMMM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)
));
你可以舉一個例子使用我在問題中添加的代碼嗎? –
謝謝,爲了您的快速回答,但我已經嘗試過了,而'F'並沒有被Symfony解釋。 –
這一定是因爲'date()'實際上沒有被使用。這個類:http://www.php.net/manual/en/class.intldateformatter.php被用來代替 – greg0ire