I have been struggling with Yii to get localized date time value to display. So I figured I’d go back to basics.
I was trying $date = new DateTime(date('Y-m-d H:i:s'));
but that was 6 hours off? So then I switched to $date = new DateTime("now", new DateTimeZone('America/New_York'));
which works properly.
Now in Yii, I’ve set my config to include things like
So I thought I could use some builtin function such as asDatetime() but haven’t been able to figure it out. Could someone offer any guidance on the matter. Is using traditional PHP the way to do this, or since Yii already has the locale/timezone it has a better solution to offer?
Correction, it does work, it appears my formatter values were incorrect
so doing something like the following works perfectly. Yii::$app->formatter->asDate('now') Yii::$app->formatter->asTime('now') Yii::$app->formatter->asDateTime('now')