asDateTime() not converting to timezone

in my main.php i have this

'formatter' => [
            'class' => 'yii\i18n\Formatter',
            'dateFormat' => 'php:j M Y',
            'datetimeFormat' => 'php:d/m/Y h:i a',
            'timeFormat' => 'php:H:i A',
            'defaultTimeZone' => 'Asia/Singapore',

in my view

<?= Yii::$app->formatter->asDateTime('2022-06-14 11:47:08'); ?> output is 14/06/2022 11:47 am

The time in my database is UTC, and the output doesn’t change to +8GMT. It’s still in UTC. What am i missing here? Thank you.

I don’t know but to me it looks like you should use timeZone for the expected zone.
(defaultTimeZone for the source zone)


thanks! totally missed this.

had to set

'defaultTimeZone' => 'UTC',
'timeZone' => 'Asia/Singapore',

works now.

1 Like