php - Displaying current system date and time -




how show current system (pc) time on form

right i'm using datetimepicker, wanna try when i'm going create in form "time_start" automatically time being used on pc.

<?= $form->field($model, 'time_start')->widget(     datetimepicker::classname(), [         'options'       => [ 'placeholder' => 'render time' ],         'pluginoptions' => [ 'autoclose' => true, ]     ] ); ?> 

you can assign value $model->time_start directly in controller before call render ..

so problem can managed in controlleraction using php functin assign value need eg in actioncreate

public function actioncreate() {     $model = new mymodel();      if ($model->load(yii::$app->request->post()) && $model->save()) {         return $this->redirect(['view', 'id' => $model->id]);     } else {         //  assign the date , time of server code runs on.         $model->time_start =  date("d-m-y h:i:s");         return $this->render('create', [             'model' => $model,         ]);     } } 

or if need specific timezone

public function actioncreate() {     $model = new mymodel();      if ($model->load(yii::$app->request->post()) && $model->save()) {         return $this->redirect(['view', 'id' => $model->id]);     } else {         //  assign the date , time of server code runs on.         //           $my_date = new datetime("now", new datetimezone('america/new_york') );          $model->time_start =   $my_date;         return $this->render('create', [             'model' => $model,         ]);     } } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -