$formatter = \Yii::$app->formatter;
// output: January 1, 2014
echo $formatter->asDate('2014-01-01', 'long');
// output: 12.50%
echo $formatter->asPercent(0.125, 2); // output: <a href="mailto:cebe@example.com">cebe@example.com</a>
echo $formatter->asEmail('cebe@example.com'); // output: Yes
echo $formatter->asBoolean(true); // it also handles display of null values: // output: (Not set
echo $formatter->asDate(null);
// output: January 1, 2014
echo Yii::$app->formatter->format('2014-01-01', 'date'); // you can also use an array to specify parameters for the format method: // `2` is the value for the $decimals parameter of the asPercent()-method. // output: 12.50%
echo Yii::$app->formatter->format(0.125, ['percent', 2]);
echo Yii::$app->formatter->asTime(1412599260);
// 14:41:00 // formatting a datetime string (in UTC) as a time
echo Yii::$app->formatter->asTime('2014-10-06 12:41:00'); // 14:41:00 // formatting a datetime string (in CEST) as a time
echo Yii::$app->formatter->asTime('2014-10-06 14:41:00 CEST'); // 14:41:00
Yii::$app->formatter->locale = 'en-US';
echo Yii::$app->formatter->asDate('2014-01-01'); // output: January 1, 2014