Answer the question
In order to leave comments, you need to log in
How to make sure that dates do not get lost in YII2?
To display dates on the site, I use Yii::$app->formatter->asDate(). The data type in mysql database is DATE. For some reason, every night around 11:00 pm, the dates jump one day forward. For example, it was 01 Aug - 14 Aug 2016 became 02 Aug - 15 Aug 2016. After a few hours everything is back to normal. What can be wrong?
I output the dates like this:
if ($this->end_date != false) {
return Yii::$app->formatter->asDate($this->start_date, 'php:d M') . ' - ' . Yii::$app->formatter->asDate($this->end_date, 'php:d M Y');
} else {
return Yii::$app->formatter->asDate($this->start_date, 'php:d M');
}
'components' => [
'formatter' => [
'defaultTimeZone' => 'Europe/Moscow'
],
...
Answer the question
In order to leave comments, you need to log in
The problem was related to the clock change on October 26, 2014. It was solved by updating the libicu52 library.
Вы указываете только у компонента formatter, лучше задавать в целом по системе, т.е. заходите в main.php и одним из параметров:
+
если у вас какой-нибудь шаблон advanced, т.е. несколько папок на проект (common, console, frontend), то это надо указать во всех конфигах.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question