Created
December 13, 2018 03:46
-
-
Save webinista/08a03133759bb3e6acbfa1d900c0f93d to your computer and use it in GitHub Desktop.
PHP: Convert an ISO 8601 duration / date (Such as the one YouTube uses) interval to seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function iso8601ToSeconds($input) { | |
$duration = new DateInterval($input); | |
$hours_to_seconds = $duration->h * 60 * 60; | |
$minutes_to_seconds = $duration->i * 60; | |
$seconds = $duration->s; | |
return $hours_to_seconds + $minutes_to_seconds + $seconds; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work.