2013-11-21 73 views
-1

實施例ⅰ具有在php中獲取格式'Y-m-d H:i:s'的區別時間?

$time1 = "2013-11-21 12:59:00"; 
$time2 = "2013-11-21 13:01:00"; 

如何獲得上述這個格式的兩個時間的差 「Y-M-d H:I:的」 ??

+0

它已經在格式 – sectus

+0

@sectus你是什麼意思?我試圖用time1減少time2但結果不正確 –

+3

如果我每次都有一個鎳,這個問題已被問...... –

回答

1
$time1 = new DateTime('2013-11-21 12:59:00'); 
$time2 = new DateTime('2013-11-21 13:01:00'); 
$interval = $time1->diff($time2); 

echo $interval->y . " Year " .$interval->m . " Month " .$interval->d ." Days ". $interval->h . " Hours, " . $interval->i." Mintues, ".$interval->s." seconds <br/>"; 
0
$time1 = strtotime("2013-11-21 12:59:00"); 
$time2 = strtotime("2013-11-21 12:59:00"); 
$diff = date("Y-m-d H:i:s", $time2-$time1); 
echo $diff; 
3

試試這個:

$date1 = new DateTime("2013-11-21 12:59:00"); 
    $date2 = new DateTime("2013-11-21 13:01:00"); 
    $interval = $date1->diff($date2); 
echo "DIFF: ".$interval->format("%Y-%m-%d %H:%i:%s"); 
相關問題