I’ve searched other the forum for date formatting examples.
I’ve found some examples and extensions like DateTimeI18NBehavior and FormatDateTimeBehavior. All this stuff looks great but i can’t manage to get it work.
so i write this simple code to test the basic idea :
I set language in config/main.php :
‘sourceLanguage’=>‘fr_fr’,
‘language’=>‘fr_fr’,
$;
$dateToLocale=Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($date, 'yyyy-MM-dd'),'medium',null);
$dateBackToMySQL=date('Y-m-d', CDateTimeParser::parse($dateToLocale, Yii::app()->locale->dateFormat));
echo 'My date: '.$date.'<br/>';
echo 'Yii::app()->locale->dateFormat = '.Yii::app()->locale->dateFormat.'<br/>';
echo 'My date to locale: '.$dateToLocale.'<br/>';
echo 'My date back to MySQL format: '.$dateBackToMySQL.'<br/>';
Result is :
My date: 2012-02-15
Yii::app()->locale->dateFormat = d MMM y
My date to locale: 15 févr. 2012
My date back to MySQL format: 1970-01-01
After i had a look at CDateTimeParser documentation it seems to be a normal result as CDateTimeParser does not understand pattern MMM.
But as Yii::app()->dateFormatter->formatDateTime used with ‘medium’ date width returns a date according to the pattern d MMM y, i don’t understand how this example and the above extensions mentionned can work. and it seems it should work according to several posts on the forum.
any idea?