Answer the question
In order to leave comments, you need to log in
Yii2. How to display date depending on timeZone?
How to display the date depending on the user's timeZone?
Answer the question
In order to leave comments, you need to log in
config/main.php - here you can adjust the output format
return [
'timeZone' => 'Europe/Minsk',
'components' => [
'formatter' => [
'dateFormat' => 'd.MM.yyyy',
'timeFormat' => 'H:mm:ss',
'datetimeFormat' => 'd.MM.yyyy H:mm',
],
],
];
Yii::$app->getFormatter()->asDate(time());
Yii::$app->getFormatter()->asDatetime(time())
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'created_at:datetime',
],
]); ?>
LAV45 LAV45
config/main.php - here you can adjust the output formatreturn [ 'components' => [ 'timeZone' => 'Europe/Minsk', 'formatter' => [ 'dateFormat' => 'd.MM.Y', 'timeFormat' => 'H:mm:ss', 'datetimeFormat' => 'd.MM.Y H:mm', ], ], ];
Not quite right!return [ 'timeZone' => 'Europe/Minsk', 'formatter' => [ 'dateFormat' => 'd.MM.Y', 'timeFormat' => 'H:mm:ss', 'datetimeFormat' => 'd.MM.Y H:mm', ], ];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question