Yii2 saves time as UTC for the database, but displays in a different time zone

Is there an easy way to save the date and time in UTC, but when do you display the dates and times to convert them to specific time zones? I added

'formatter'  => [
    'class' => 'yii\i18n\Formatter',
    'timeZone'        => 'America/New York',
],

In my configuration, but everything is now saved, as in the EST time zone in the database. I want the database to always be UTC and control the time zone display when printing time and date in php.

Basically, I would like to formatterhave a separate parameter for controlling the format included in the database, and another parameter for controlling the format for display purposes (since users can be in different time zones).

+4
source share
1

Yii Yii2?

Yii2, , :

$config = [
    'timeZone' => 'Europe/London',
    // other config goes here
];

, PHP, . , strtotime , UTC, .

formatter UTC, :

$model->date = Yii::$app->formatter->asTime('2014-10-06 14:41:00 UTC');

PHP, , , . :

echo date("d. M. Y.", $your_date);
+1

Source: https://habr.com/ru/post/1657148/


All Articles