0

I have the following code in a template:

        <?= $this->Form->date('selected_date', ['required' => true]) ?>

This displays a lovely new dynamic date picker, but with the US format "mm/dd/yyyy". What I want is "dd/mm/YYYY"

In app.php I've set the APP_DEFAULT_LOCALE to en-GB. In AppController.php I've set the following:

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

How do I change the format? I can't find anything in the docs or online.

ndm
  • 59,784
  • 9
  • 71
  • 110
bemoore
  • 84
  • 7

1 Answers1

1

You can't change it, at least there's no reliable, cross browser/device compatible way, the control is rendered by the browser, and the current state of things is that browsers use the locale the browser currently runs in to format the control.

If you want something solid, then you'll have to use a custom JavaScript datepicker. If you want to walk on the edge, look into web components.

See also Is there any way to change input type="date" format?.

ndm
  • 59,784
  • 9
  • 71
  • 110