2012-11-09 66 views
0

的區別我有一個包含時間兩個字符串,如:減去兩個字符串變量

'ftime1' => string '17:44' (length=5) 
    'ftime2' => string '18:19' (length=5) 

我需要計算frime2和ftime1之間的差別,所以結果是分鐘

我已經試過

$struct[$i]['ttime'] = time($struct[$i]['ftime2']) - time($struct[$i]['ftime1']); 
$struct[$i]['ttime2'] = strtotime($struct[$i]['ftime2']) - strtotime($struct[$i]['ftime1']); 
$struct[$i]['ttime3'] = $struct[$i]['ftime2'] - $struct[$i]['ftime1']; 

這導致:

'ttime' => int 0 
    'ttime2' => int 2100 
    'ttime3' => int 1 
+0

'ttime2/60' min? – air4x

+3

'時間()'不會做你明顯認爲它做的事情。它甚至沒有爭論! http://php.net/time – deceze

+1

真的,因爲decez基本上說,RTFM ... time()沒有參數,只是返回當前的時間戳。 –

回答

2

strtotime轉換成字符串時間戳這是對seconds..so的差異也將在seconds..do / 60幾分鐘..

(strtotime($struct[$i]['ftime2']) - strtotime($struct[$i]['ftime1']))/60; 

和時間功能不表現THA它返回當前的Unix時間戳,並且不接受任何參數。