php中的strtime不给出精确的时间



我想将DB的时间与当前时间进行比较。在DB中存储时间的Strttime工作正常。但是,当我使用strttime获得当前时间时,这并没有给我确切的时间。我从在线网站上检查了一下。这是我的代码:

此部分存储时间在DB中:

public function Add($data)
{
    foreach ($data['check'] as $key => $value) {
        foreach ($value['in'] as $k => $v) {
            if(!empty($value['in'][$k])) {
                $allocate = array(
                    'check_in' => strtotime(date('h:i A', strtotime($value['in'][$k]))),
                    'check_out' =>strtotime(date('h:i A', strtotime($value['out'][$k]))),
                    //'check_in' => strtotime($value['in'][$k]),
                    //'check_out' =>strtotime($value['out'][$k]),
                    'Days_id' => $key,
                    'User_id' => $data['Users']
                );
                $this->db->insert('assgin_days',$allocate);
            }
        }
    }
}

此部分将DB与当前时间进行比较:

public function checkuserlogin()
{
    $string = exec('getmac');
    $mac = substr($string, 0, 17); 
    $day_of_week = date('N');
    date_default_timezone_set("Asia/Karachi");
    $time = strtotime(date('h:i A'));
    $timee = date('h:i A');
    $id=$this->user_model->userInfo("id");
    $data=$this->db->query("SELECT admin.first_name, days.d_name FROM assgin_days INNER JOIN admin ON admin.id= assgin_days.User_id inner join days ON days.D_id= assgin_days.Days_id where assgin_days.User_id = $id and assgin_days.Days_id =$day_of_week and assgin_days.check_in =<$time and assgin_days.check_out >=$time and assgin_days.is_delete=0")->result_array();
}

需要使用日期('g:i',strtotime($ value ['in'''] [$ k])),而不是date('H:i',strtotime($ value ['in'] [$ k]),它将将日期更改为24小时的格式,然后可以轻松存储和可比较。

 public function Add($data){
    foreach ($data['check'] as $key => $value) {
    foreach ($value['in'] as $k => $v) {
    if(!empty($value['in'][$k]))
    {
    $allocate = array(
    'check_in' => date('G:i', strtotime($value['in'][$k])),
    'check_out' =>date('G:i', strtotime($value['out'][$k])),
    'Days_id' => $key,
    'User_id' => $data['Users']);
    $this->db->insert('assgin_days',$allocate);
    }
    }
    }
  } 

相关内容

  • 没有找到相关文章

最新更新