Home  >  Article  >  PHP Framework  >  How to convert time format in yii framework

How to convert time format in yii framework

王林
王林Original
2020-02-27 11:42:382412browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn