[英]How to compare hours and minutes
I would like to check if the user has logged into site on time or late suppose the user have to login before 10:15 and he log in at 11:00我想检查用户是否按时或延迟登录网站假设用户必须在 10:15 之前登录并且他在 11:00 登录
how can i just know if he is late or early or on time?我怎么知道他是迟到还是早到或准时?
should i use strtotime ?我应该使用 strtotime 吗?
You can make use of strtotime function which returns the Current Time as a Unix Timestamp.您可以使用 strtotime 函数,该函数将当前时间作为 Unix 时间戳返回。
Compare the two values to check if he/she has logged in late or not.比较这两个值以检查他/她是否延迟登录。
Try this尝试这个
getTimeDifference(10:15,11:00)
function getTimeDifference($dtime,$atime)
{
$nextDay=$dtime>$atime?1:0;
$dep=EXPLODE(':',$dtime);
$arr=EXPLODE(':',$atime);
$diff=abs(MKTIME($dep[0],$dep[1],0,DATE('n'),DATE('j'),DATE('y'))-MKTIME($arr[0],$arr[1],0,DATE('n'),DATE('j')+$nextDay,DATE('y')));
$hours=FLOOR($diff/(60*60));
$mins=FLOOR(($diff-($hours*60*60))/(60));
$secs=FLOOR(($diff-(($hours*60*60)+($mins*60))));
IF(STRLEN($hours)<2){$hours="0".$hours;}
IF(STRLEN($mins)<2){$mins="0".$mins;}
IF(STRLEN($secs)<2){$secs="0".$secs;}
//RETURN $hours.':'.$mins.':'.$secs;
return $hours.':'.$mins;
}
$timeString="your time string"
$currTime = strtotime($timeString)
$inTime = strtotime("06/01/2017 11:00AM")
$early=($currTime >= $inTime)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.