0

I have this kind of string:

$duration = "00:20:55.60000";

It was extracted from a video using ffmpeg. I need to convert it to seconds.

I had tried this: strtotime("1970-01-01 $duration UTC"); (I get it from here) but it's not working. May be because it is containing dot at the seconds part.

Is there a way to convert that string to seconds?

Community
  • 1
  • 1
Ari
  • 4,643
  • 5
  • 36
  • 52

3 Answers3

0
$duration = "00:20:55.60000";
echo date('H:i:s', strtotime($duration));
bfontaine
  • 18,169
  • 13
  • 73
  • 107
Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40
0

Try this:

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

Or

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

Working Code

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

just use DateTime class.

$now = '00:20:55.60000';
$timevalue = new DateTime($now);
$onlytime = $timevalue->format('H:i:s');
echo $onlytime ;
reza
  • 1,507
  • 2
  • 12
  • 17