php 中的 strtotime 未给出确切时间
strtotime in php not giving exact time
我想将来自数据库的时间与当前时间进行比较。用于在数据库中存储时间的 strtotime 工作正常。但是当我使用 strtotime 获取当前时间时,它并没有给我确切的时间。我从一个在线网站上查过。这是我的代码:
这部分在数据库中存储时间:
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);
}
}
}
}
这部分将数据库中的时间与当前时间进行比较:
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();
}
需要使用date('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);
}
}
}
}
我想将来自数据库的时间与当前时间进行比较。用于在数据库中存储时间的 strtotime 工作正常。但是当我使用 strtotime 获取当前时间时,它并没有给我确切的时间。我从一个在线网站上查过。这是我的代码:
这部分在数据库中存储时间:
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);
}
}
}
}
这部分将数据库中的时间与当前时间进行比较:
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();
}
需要使用date('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);
}
}
}
}