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,155
  • 3
  • 34
  • 49

3 Answers3

0
$duration = "00:20:55.60000";
echo date('H:i:s', strtotime($duration));
bfontaine
  • 16,410
  • 12
  • 69
  • 92
Rushil K. Pachchigar
  • 1,175
  • 2
  • 18
  • 38
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
  • 24,624
  • 3
  • 35
  • 55
0

just use DateTime class.

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