timeZone is configured, formatter still showing 3 hours ahead?

I’m having an issue with timezones.

I read through this:

I have an advanced-app layout and common/main.php includes:

'timeZone' => 'America/New_York',

To test things out, I have this code:

$tz = Yii::$app->timeZone;
echo '<div class="col-md-12" style="text-align:right;">';
echo Yii::$app->formatter->asDate('now', 'php:F j, Y, g:i a') . " ($tz)";
echo '</div>';

As I write this, it is 10:53 PM EDT. However, the output of this code is:

September 19, 2021, 2:53 AM (America/New_York)

I included the TZ in the output to be sure my configuration was read by yii2.

I’m unclear why the output is 3 hours ahead, even though I have my timeZone configured. I assume I’m doing something goofy, or missing something important, but I am definitely not seeing it.

If you want to get the date with the time while providing an input as not a date with time (like your now) you need to call asDatetime, otherwise app will use default timezone which by default is set to UTC.