Yii2 Format 如何使用
Posted Yeah,程序猿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Yii2 Format 如何使用相关的知识,希望对你有一定的参考价值。
$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:[email protected]">[email protected]</a>
echo $formatter->asEmail(‘[email protected]‘); // 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
以上是关于Yii2 Format 如何使用的主要内容,如果未能解决你的问题,请参考以下文章