public static function timetoDuration($time)
    {
        $duration = 'PT';

        $regexp = "/^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?$/";

        if (preg_match($regexp, $time, $matches)) {
            $duration .= intval($matches[1]) . 'H' . intval($matches[2]) . 'M';
            $duration .= isset($matches[4])
                ? intval($matches[3]) . $matches[4] . 'S'
                : intval($matches[3]) . 'S';
        } else {
            $duration .= '0S';
        }

        return $duration;
    }
public static function timetoDuration($time)
    {
        $duration = 'PT';

        $regexp = "/^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?$/";

        if (preg_match($regexp, $time, $matches)) {
            $duration .= intval($matches[1]) . 'H' . intval($matches[2]) . 'M';
            $duration .= isset($matches[4])
                ? intval($matches[3]) . $matches[4] . 'S'
                : intval($matches[3]) . 'S';
        } else {
            $duration .= '0S';
        }

        return $duration;
    }
public static function timetoDuration ( $ time ) { $ duration = 'PT' ; $ regexp = "/^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?$/" ; if ( preg_match ( $ regexp , $ time , $ matches ) ) { $ duration .= intval ( $ matches [ 1 ] ) . 'H' . intval ( $ matches [ 2 ] ) . 'M' ; $ duration .= isset ( $ matches [ 4 ] ) ? intval ( $ matches [ 3 ] ) . $ matches [ 4 ] . 'S' : intval ( $ matches [ 3 ] ) . 'S' ; } else { $ duration .= '0S' ; } return $ duration ; }
Converts a time string to an ISO8601 duration
@param string $time as hh:mm:ss.micros
@return string the ISO duration
Converts a time string to an ISO8601 duration