how can I block Yii::$app->formatter->asDate() to convert the datetime I pass to it?

I wanted just to use Yii::$app->formatter->asDate() to format how the datetime should be displayed without converting to another timezone; but what I noticed is it also converting the passed datetime to the application timzone.

So how can I block that behaviour and just receive my datetime as it but displayed accordling to the application language(I thought formatter is just for displaying accordling to the current language)?

I’ve noticed that Yii::$app->formatter->asDate() is converting the date from the one timezone to the application’s current timezone.

What I want is just to format date according to this format php:D d-M-Y H:i:s without converting the date to a timezone because it display the day and month in current language.

Here is what I have in my code:


echo Yii::$app->formatter->asDatetime('2016-3-1 10:08:27','php:D d-M-Y H:i:s');

My timezone is

; 2016-3-1 10:08:27 is what mysql database is giving me meaning it is already in my timezone. The problem is the up echo is displaying

instead of

but if I don’t use Yii::$app->formatter->asDatetime it is displaying correctly.

How can I do that?

How can I solve this problem?

Set the default time zone?

I tend to have this in ‘index.php’ :


date_default_timezone_set('UTC');



You can probably set it to Nairobi :)

It doesn’t work and one thing is before even call


Yii::$app->formatter->asDate()

if I try to


echo Yii::$app->getTimeZone()

it is returning the correct timezone.

I am using Yii2 timezone extension to get client timezone and it is getting it perfectly.

I guess that what you see is Yii displaying the time using UTC - you need to tell the formatter what timezone you want it to use:

http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#$defaultTimeZone-detail

I haven’t really used this myself yet - I am using PHP directly for this - but I think that is the problem. Tell it to use your timezone.

To it I have to specify the timezone explicitly since the default timezone(UTC) is not the same with my timezone(africa/Nairobi). Here is how to specify:


Yii::$app->formatter->asDatetime('2016-3-1 10:08:27' . Yii::$app->getTimeZone(),'php:D d-M-Y H:i:s');

//Result is 2016-3-1 10:08:27



I have UCI version 51.1 on my local computer but online UCI version 54.1; the problem is the previous solution is working on my local computer but online if I add the timezone it displays the date in UTC and if I remove the timezone it’s displaying the date correctly.

I try to accuse the version but have not found enough theory to support the accusion.

I really don’t get it!!!! I have to pass through all my code to remove the timezone I added; before doing that I wanted to know if my accusation is correct and move on.