php - DateTimeZone::__construct(): Unknown or bad timezone (Asia/Jakarta) -
i want made date can save in database. date automatic save in database, in cgridview date not appear in date now. example : date "06 dec 2014", in cgridview appear "05 dec 2014" (without quotation mark). want date save in database , appear in cgridview date now.
how fix it?
this code : ---------- **in model torque** public function beforesave() { if(parent::beforesave()) { if($this->isnewrecord) { $this->create_time = $this->update_time = strtotime( yii::app()->localtime->timezone = 'asia/jakarta'); $this->create_time = $this->update_time = date ('y-m-d', $this->create_time); $this->id_user=yii::app()->user->id; $criteria=new cdbcriteria; $criteria->select='nomor'; $criteria->limit=1; $criteria->order='nomor desc'; $last=$this->find($criteria); if($last) { $newid = $last->nomor + 1; } else { $newid='1'; } $this->nomor=$newid; } else { $this->update_time = yii::app()->localtime->fromlocaldatetime( $this->update_time,'short'); $this->id_user=yii::app()->user->id; } return true; } else { return false; } } ---------- **my components** class localtime.php public function getlocale() { // localdatetimezone if been set $locale=yii::app()->getglobalstate(self::_globallocale); // default yii language if isn't - note yii::app()->setlanguage doesn't save globally if ($locale===null) $locale=yii::app()->language; return($locale); } // local now() function // can use of php date() formats return local date/time value // http://php.net/manual/en/function.date.php public function getlocalnow($format=date_iso8601) { $localnow=new datetime(null,$this->localdatetimezone); return $localnow->format($format); } ---------- **in torquecontroller** public function actioncreate() { $model=new torquebmw; // uncomment following line if ajax validation needed // $this->performajaxvalidation($model); if(isset($_post['torquebmw'])) { $model->attributes=$_post['torquebmw']; if($model->save()) $this->redirect(array('view','id'=>$model->id_torque)); } $this->render('create',array( 'model'=>$model, )); }
my cgridview
array ( 'name'=>'tool', 'value'=>$model->idtool->nm_tool, ), array ( 'name'=>'ref. calibration', 'value'=>$model->idrefcalibration->nm_ref_calibration, ), array( 'name'=>'id_user', 'value'=>$model->iduser->username, ), 'create_time', 'update_time', ),
asia/akarta
not valid timezone. have typo somewhere. either in code or in php settings (php.ini). search asia/akarta
, change asia/jakarta
.
Comments
Post a Comment