Answer the question
In order to leave comments, you need to log in
The date is not displayed correctly when using the DateControl module (kartik-v)?
Good afternoon! I use the DateControl module, I save the values in the unix format, I display them in the format 07/05/2020 and the default value is 01/01/1970. At the same time, if you save not in unix format, then everything is fine
Settings in the web config
'datecontrol' => [
'class' => 'kartik\datecontrol\Module',
'displaySettings' => [
Module::FORMAT_DATE => 'dd.mm.yyyy',
Module::FORMAT_TIME => 'HH:mm:ss a',
Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss a',
],
'saveSettings' => [
Module::FORMAT_DATE => 'php:U',
Module::FORMAT_TIME => 'php:H:i:s',
Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
],
'displayTimezone' => 'Europe/Moscow',
'saveTimezone' => 'UTC',
'autoWidget' => true,
'ajaxConversion' => true,
'autoWidgetSettings' => [
Module::FORMAT_DATE => ['type'=>2, 'pluginOptions'=>['autoclose'=>true]],
Module::FORMAT_DATETIME => [], // setup if needed
Module::FORMAT_TIME => [], // setup if needed
],
'widgetSettings' => [
Module::FORMAT_DATE => [
'options' => [
'dateFormat' => 'php:d.m.Y',
'options' => ['class'=>'form-control'],
],
]
]
]
<?php
echo $form->field($model, 'date')->widget(DateControl::classname(), [
'value'=>date("d.m.Y"),
'type'=>DateControl::FORMAT_DATE,
'displayFormat' => 'php:d.m.Y'
]);
?>
Answer the question
In order to leave comments, you need to log in
You need to convert the date to unix format before saving it to the database. You can do it like this:
(new DateTimeImmutable('05.07.2020'))->getTimestamp();
Is the time zone set globally in the config?
'timezone' => 'UTC',
'components'=>[
'formatter' => [
'timeZone' => 'America/Chicago',
],
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question