我在模板中有以下代码:
<?= $this->Form->date('selected_date', ['required' => true]) ?>
这将显示一个可爱的新动态日期选择器,但美国格式为“ mm / dd / yyyy”。我想要的是“ dd / mm / YYYY”
在app.php中,我已将APP_DEFAULT_LOCALE设置为en-GB。 在AppController.php中,我设置了以下内容:
I18n::setLocale('en-GB');
Time::setDefaultLocale('en-GB'); // For any mutable DateTime
FrozenTime::setDefaultLocale('en-GB'); // For any immutable DateTime
Date::setDefaultLocale('en-GB'); // For any mutable Date
FrozenDate::setDefaultLocale('en-GB'); // For any immutable Date
如何更改格式?我在文档或在线中找不到任何内容。
答案 0 :(得分:1)
您无法更改它,至少没有可靠的,跨浏览器/设备兼容的方式,控件由浏览器呈现,并且当前状态是浏览器使用浏览器当前运行的语言环境进行格式化控件。
如果您想要一些坚固的东西,则必须使用自定义JavaScript日期选择器。如果您想走在边缘,请查看web components。