欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

工具代码收藏 -- 判断是否是同一天

程序员文章站 2024-03-20 21:31:52
...
    public static function isSameDay($time1, $time2, $sepHour = 0) {
        $d1 = date('Y-m-d', $time1); 
        $d2 = date('Y-m-d', $time2);
        $h1 = date('H', $time1);
        $h2 = date('H', $time2);

        if($d1 == $d2) {
            if($h1 < $sepHour and $h2 < $sepHour) {
                return true;
            } else if($h1 >= $sepHour and $h2 >= $sepHour){
                return true;
            } else {
                return false;
            }
        } else {
            $daySec = 3600 * 24;
            if(date('Y-m-d', $time1 - $daySec) == $d2 and $h1 < $sepHour and $h2 >= $sepHour) {
                return true;
            } else if(date('Y-m-d', $time2 - $daySec) == $d1 and $h2 < $sepHour and $h1 >= $sepHour) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }