Yii2 View DateTime Format (d-m-Y H:i:s) But When Save/update in DB Change format to Y-m-d H:i:s

后端 未结 5 1529
礼貌的吻别
礼貌的吻别 2021-02-06 04:26

I\'m Using Kartik DateTimePicker Extension

field($model, \'Created\')->widget(DateTimePicker::classname(),[
        \'model\' => $model,
          


        
5条回答
  •  一整个雨季
    2021-02-06 05:00

    I have simple code, in behavior:

     public function behaviors() {
        return [
           [ 'class' => \yii\behaviors\TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                ],
                // if you're using datetime instead of UNIX timestamp:
                 'value' => new Expression('NOW()'),
           ]
        ];
    }
    

    for rules:

     public function behaviors() {
        return [
           [ 'class' => \yii\behaviors\TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                ],
                // if you're using datetime instead of UNIX timestamp:
                 'value' => new Expression('NOW()'),
           ]
        ];
    }
    

提交回复
热议问题