Very useful tools in Yii are CDateTimeParser and CDateFormatter
Let's assume we have date and time formatted like this: "28/02/2018 14:10"
It might be output from MySql for example.
How to convert it to "28 feb 2018, 14:10" without any hassle?
CDateFormatter
CDateTimeParser
Let's assume we have date and time formatted like this: "28/02/2018 14:10"
It might be output from MySql for example.
How to convert it to "28 feb 2018, 14:10" without any hassle?
<?php $unixtime=CDateTimeParser::parse($model->time,'dd/MM/yyyy hh:mm'); echo Yii::app()->dateFormatter->format('dd MMM yyyy, hh:mm',$unixtime); ?>More:
CDateFormatter
CDateTimeParser
Newbie question:
ReplyDeleteWhy can't we use CDateFormatter::format() just like CDateTimeParser::parse()?