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: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

上一篇:Cobbler自动化批量安装linux服务器的操作记录


下一篇:MySQL 安装和启动服务,“本地计算机 上的 MySQL 服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止。”