<?php

function elapsedTime($startTime = '', $endTime = '',$format="SECONDS",$decimals = 4)
{
    if (!$startTime){
        return '';
    }

    if (!$endTime){
        $endTime = microtime();
    }

    list($startMicroSecond, $startSecond) = explode(' ', $startTime);
    list($endMicroSecond, $endSecond) = explode(' ', $endTime);
    
    if($format){
        $format = strtoupper($format);
    }
    if($format == 'SECONDS'){        
        $timeVal  =  number_format((($endMicroSecond + $endSecond) - ($startMicroSecond + $startSecond)),$decimals)." SECONDS";
    }
    else if($format == 'MINUTS'){
        $timeVal  =  number_format((($endMicroSecond + $endSecond) - ($startMicroSecond + $startSecond))/60 ,$decimals). " MINUTS";
    }        
    else if($format == 'HOURS'){
        $timeVal  =  number_format((($endMicroSecond + $endSecond) - ($startMicroSecond + $startSecond))/3600,$decimals). " HOURS";
    }
    else if($format == 'DAYS'){        
        $timeVal  =  number_format(((($endMicroSecond + $endSecond) - ($startMicroSecond + $startSecond))/3600)/24,$decimals)." DAYS";
    }        
    
    return $timeVal;        
}

$a = "0.66121500 1395993490";
$b = microtime();

echo '<p>Elapsed Time  in Days: '.elapsedTime($a,$b,"DAYS",2).'</p>';
echo '<p>Elapsed Time  in Hours: '.elapsedTime($a,$b,"HOURS",2).'</p>';
echo '<p>Elapsed Time  in Minuts: '.elapsedTime($a,$b,"MINUTS",2).'</p>';
echo '<p>Elapsed Time  in Seconds: '.elapsedTime($a,$b,"SECONDS",2).'</p>';
    
?>

Comments

apo2888 için bir cevap yazın Cevabı iptal et

E-posta hesabınız yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Şu HTML etiketlerini ve özelliklerini kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>