Reputation: 123
This is my code located inside a Template. The dateTime control its displaying the dateFormat 'M-D-Y' and timeFormat '12' (AM/PM). I need to change it to the dateFormat 'D-M-Y' and timeFormat '24'.
I searched for the options in 4.x but can't find anything useful. In older versions (2.x and 3.9) I was able to use
FormHelper::dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $attributes = array())
but now it's
Cake\View\Helper\FormHelper::dateTime($fieldName, $options = [])
.
I've tried using 'dateFormat' and 'timeFormat' inside the options array with no success.
<?= $this->Form->dateTime('from', ['default' => true]); ?>
<?= $this->Form->dateTime('from', 'DMY', '24', ['default' => true]); ?> //not working
<?= $this->Form->dateTime('from', ['default' => true, 'dateFormat' => 'DMY', 'timeFormat' => 24]); ?> //doesn't modify dateFormat or timeFormat
<?= $this->Form->dateTime('from', ['default' => true, 'date_format' => 'DMY', 'time_format' => 24]); ?> //doesn't modify dateFormat or timeFormat
This is the config of the app.php
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'es_AR'),
'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'America/Argentina/Buenos_Aires'),
Upvotes: 0
Views: 297
Reputation: 60453
FormHelper::dateTime()
creates input elements of the type datetime-local
, you cannot control the display format of these input types (in case supported by the browser in the first place), this is handled by the browser and depends on the user's Browser/OS locale config.
If you need more control over the display format, use a text
input instead, and a JavaScript based datetime picker that allows you to configure the display format.
Upvotes: 1