DateTimeZone :: __ construct():时区不明(或亚洲/雅加达)

时间:2014-12-05 23:44:19

标签: php yii

我想将日期保存在我的数据库中。 date自动保存在数据库中,但在CGridView中日期现在不出现在日期中。例如:日期“2014年12月6日”,但在CGridView中出现“2014年12月5日”(不带引号)。我想在数据库中保存日期并立即出现在CGridView日期。

如何解决?


this my code :

----------
**in my 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()
    {
        // Get the localDateTimeZone if its been set
        $locale=Yii::app()->getGlobalState(self::_globalLocale);

        // Default to yii language if it isn't - note that Yii::app()->setLanguage doesn't save globally
        if ($locale===null)
            $locale=Yii::app()->language;

        return($locale);
    }

    // Local now() function
    // Can use any of the php date() formats to return the 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 my TorqueController**

    public function actionCreate()
    {
        $model=new TorqueBmw;

        // Uncomment the following line if AJAX validation is 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,
        ));
    }

我的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',
),

1 个答案:

答案 0 :(得分:2)

Asia/akarta不是有效的时区。你可能在某个地方有一个错字。在您的代码或PHP设置(php.ini)中。搜索Asia/akarta并将其更改为Asia/Jakarta