Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
时间CAKEPHP3以不同的值保存在数据库中_Php_Angularjs_Cakephp - Fatal编程技术网

时间CAKEPHP3以不同的值保存在数据库中

时间CAKEPHP3以不同的值保存在数据库中,php,angularjs,cakephp,Php,Angularjs,Cakephp,我正在处理接收时间,但当数据库中的保存不同时,如果我在数据库中发送8:00 pm和12:00 am,则所有情况下的保存时间均为+4小时 从表单接收数据我从控制台得到: Thu Jan 01 1970 08:00:00 GMT-0400 (Hora estándar oeste, Sudamérica) 我正在使用angular js后端和cakephp 3: public function add() { $data = ['result' =>

我正在处理接收时间,但当数据库中的保存不同时,如果我在数据库中发送8:00 pm和12:00 am,则所有情况下的保存时间均为+4小时

从表单接收数据我从控制台得到:

Thu Jan 01 1970 08:00:00 GMT-0400 (Hora estándar oeste, Sudamérica)
我正在使用angular js后端和cakephp 3:

 public function add()
        {
            $data = ['result' => 'fail', 'id' => 'null'];
            $errors = $this->Shifts->validator()->errors($this->request->getData());
            if(empty($errors))
            {
                $shifts = $this->Shifts->newEntity($this->request->getData());
                $date_entrada = strtotime($this->request->getData('hora_entrada'));
                $date_salida = strtotime($this->request->getData('hora_salida'));
                $shifts->hora_entrada = date('H:i:s', $date_entrada);
                $shifts->hora_salida = date('H:i:s', $date_salida);
                if ($this->Shifts->save($shifts))
                {
                    $data = ['result' => 'success', 'id' => $shifts->id];
                }
            } else {

                $data['error'] = $errors;
            }
            $this->set(compact('data'));
            $this->set('_serialize', ['data']);
        }

在config/bootsrap.php中添加以下内容

/*
 * Set server timezone to UTC. You can change it to another timezone of your
 * choice but using UTC makes time calculations / conversions easier.
 */
date_default_timezone_set('America/New_York');
签入此列表,其中是要设置的时区


关于

我认为这是因为数据库设置为使用UTC时区,所以您应该位于UTC-4时区,以便正确跟踪它添加4小时的日期。在获取信息时,应该执行相反的操作。