C
C
Carlos Rodriguez2015-02-03 18:37:42
Yii
Carlos Rodriguez, 2015-02-03 18:37:42

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

3 answer(s)
M
Max, 2015-02-03
@AloneCoder

Excellent article on the topic
habrahabr.ru/company/mailru/blog/242645

L
LAV45, 2015-02-12
@LAV45

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',
        ],
    ],
];

Output in the correct format
Yii::$app->getFormatter()->asDate(time());
Yii::$app->getFormatter()->asDatetime(time())

output in a table
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'created_at:datetime',
        ],
]); ?>

R
RAPOS, 2015-09-04
@RAPOS


LAV45 LAV45
config/main.php - here you can adjust the output format
return [
    '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 question

Ask a Question

731 491 924 answers to any question