Using CDateFormatter

Hi, could you please help a newbie with enabling CDateFormatter component in an yii app?

I added this to my protected/config/main.php:

// application components




        'class' => 'CDateFormatter',

        'params' => array('en'),




I would like to use currently selected language and not en, but it doesn’t work like this anyway. Yii throws error “Missing argument 1 for CDateFormatter::__construct()…”. So how do I correctly add CLocale instance as the $locale parameter?

Also, should I use dateFormatter in controller or in view, what is the best practice?

For the locale corresponding to the application language you can use

Yii::app()->dateFormatter-> ...


You don’t have to define it at the config file. (Only your language settings)

Thank you for your reply. I would swear that it is just what I tried to do yesterday and it didn’t work. It threw error about accessing parents method or something like that. Hmmm, strange, it works now.