我有一个mySQL数据库,存储一个人在健身房的签出和结账时间。我已经将签入和签出时间导入到我的PHP脚本中。现在我想从对方身上扣除这两个时间戳--给我剩下的时间。我想在几分钟内展示这个。
这是我的主意:
$checkOut = "2016-01-31 15:01:11";
$checkIn = "2011-01-31 15:32:35";
echo ($checkIn - $checkOut);
// I want this to display 31 minutes. 我在StackOverflow上看到了许多例子,但没有一个与我的描述相匹配,而且我也无法反向设计我找到的那些例子--因为它们使用了time()函数--我猜这需要花费当前的时间。
发布于 2016-01-25 10:49:32
您可以使用标准时间();
$checkOut = "2016-01-31 15:01:11"; // initial value
$checkIn = "2011-01-31 15:32:35"; // initial value
$checkOut_stamp = strtotime($checkOut); // Converting to unix timestamp
$checkIn_stamp = strtotime($checkIn); // Converting to unix timestamp
echo date("i", ($checkIn - $checkOut)) . 'Minute(s)';IMP备注:只有当会议记录低于59分钟时,上述方法才能工作,否则时间将被舍入,丢弃。因此,如果您的需求是以分钟为单位显示的时间比59分钟的eg. 144 minutes还要多,那么您就需要将时间除以60,如下所示。
$checkOut = "2016-01-31 15:01:11"; // initial value
$checkIn = "2011-01-31 15:32:35"; // initial value
$checkOut_stamp = strtotime($checkOut); // Converting to unix timestamp
$checkIn_stamp = strtotime($checkIn); // Converting to unix timestamp
$seconds = $checkOut_stamp - $checkIn_stamp;
if($seconds > 0){
if($seconds > 60){
$minutes = $seconds/60;
} else {
$minutes = 0;
}
} else {
$minutes = 0;
}
echo $minutes . ' Minute(s)';发布于 2016-01-25 10:49:08
$checkOut = "2016-01-31 15:01:11";
$checkIn = "2011-01-31 15:32:35";
$time = (strtotime($checkIn) - strtotime($checkOut));
echo date('i',$time);使用此代码
发布于 2016-01-25 10:55:29
如果您从数据库中获取此记录,那么您可以使用MySql函数TIMESTAMPDIFF实现它,因为这里不需要使用PHP函数。
Select TIMESTAMPDIFF(MINUTE,checkIn,checkout) as tot_diff from your_tablehttps://stackoverflow.com/questions/34990697
复制相似问题