2017-01-25 53 views
0

我有這樣的字符串:PHP - 轉換時間從HH:mm:ss格式,有一個圓點秒

$duration = "00:20:55.60000";

它使用ffmpeg視頻提取。我需要將其轉換爲秒。

我曾試過這個:strtotime("1970-01-01 $duration UTC");(我從here得到它),但它不工作。可能是因爲它在秒部分包含點。

有沒有辦法將該字符串轉換爲秒?

+1

爲什麼不爆炸,它 ':',乘第一和第二元素,然後求和值 –

+0

做'的strtotime( 「1970-01-01」 .substr($時間,0,8)。 「UTC」);'這將解決它 – JustOnUnderMillions

回答

0
$duration = "00:20:55.60000"; 
echo date('H:i:s', strtotime($duration)); 
0

試試這個:

$duration = "00:20:55.60000"; 
echo time(strtotime($duration)); 
// returns : 1485346959 

或者

echo date('H:i:s', strtotime($duration)); 
// returns: 00:20:55 

Working Code

0

只使用DateTime類。

$now = '00:20:55.60000'; 
$timevalue = new DateTime($now); 
$onlytime = $timevalue->format('H:i:s'); 
echo $onlytime ; 
相關問題