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 1528
礼貌的吻别
礼貌的吻别 2021-02-06 04:26

I\'m Using Kartik DateTimePicker Extension

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


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 05:25

    Need to just add this code before save/update model in controller.

    like,

    // ICU format
    $model->Created = Yii::$app->formatter->asDate($_POST['modelName']['Created'], 'yyyy-MM-dd HH:mm:ss'); // 2014-10-06 15:22:34
    

    OR

    // PHP date()-format
    $model->Created = Yii::$app->formatter->asDate($_POST['modelName']['Created'], 'php:Y-m-d H:i:s'); // 2014-10-06 15:22:34
    

    For more information refer this link

提交回复
热议问题