如何获得两个日期PHP 5.2的分钟间隔?

时间:2015-01-28 06:31:39

标签: php date date-difference

$curr_date = date('2015-01-28 14:23:02');
$deadtime= date('2015-01-26 15:11:00');

我遇到了麻烦的朋友?我很难将当前日期的分钟差异与死区时间相关联。你可以帮我配方奶粉吗?在此先感谢

3 个答案:

答案 0 :(得分:2)

尝试这样的事情

(strtotime($curr_date) - strtotime($deadtime))/60

答案 1 :(得分:1)

您可以通过以下功能获得全时差异

function date_getFullTimeDifference( $start, $end )
{
$uts['start']      =    strtotime( $start );
        $uts['end']        =    strtotime( $end );
        if( $uts['start']!==-1 && $uts['end']!==-1 )
        {
            if( $uts['end'] >= $uts['start'] )
            {
                $diff    =    $uts['end'] - $uts['start'];
                if( $years=intval((floor($diff/31104000))) )
                    $diff = $diff % 31104000;
                if( $months=intval((floor($diff/2592000))) )
                    $diff = $diff % 2592000;
                if( $days=intval((floor($diff/86400))) )
                    $diff = $diff % 86400;
                if( $hours=intval((floor($diff/3600))) )
                    $diff = $diff % 3600;
                if( $minutes=intval((floor($diff/60))) )
                    $diff = $diff % 60;
                $diff    =    intval( $diff );
                return( array('years'=>$years,'months'=>$months,'days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) );
            }
            else
            {
                echo "Ending date/time is earlier than the start date/time";
            }
        }
        else
        {
            echo "Invalid date/time data detected";
        }
}

答案 2 :(得分:0)

试试这个,首先设置default_timezone

date_default_timezone_set("Iran");
$timezone = date_default_timezone_get();
$waitTime=diffTime( $deadtime,$curr_date);