Home > Article > PHP Framework > How to convert time format in yii framework
Problem:
When the front page is displayed, the user selects the date through the control, generates a format such as 2016-11-01, and saves it to the database as The int type of timestamp. It needs to be converted, how to convert it?
(Recommended tutorial: yii framework)
Solution:
In the rules method in the model class, just add rules.
The specific code is as follows:
public function rules() { return [ //使用filter来处理表单中时间的格式 ['create_time' , 'filter', 'filter' => function(){ return strtotime($this->create_time); }], ['update_time' , 'filter', 'filter' => function(){ return strtotime($this->update_time); }], ]; }
Among them, "create_time" and "update_time" are two attributes in the entity class, creation time and modification time, and strtotime function is the timestamp conversion function.
For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!
The above is the detailed content of How to convert time format in yii framework. For more information, please follow other related articles on the PHP Chinese website!