将第二个持续时间更改为ISO 8601格式

how can I convert

00:00:46.70

to

T0M46S

I try

$date = new DateTime($time); echo $date->format('\P\TG\Hi\M');

but it give me something like this:

PT0H00M

Note I want duration...not date!

There is no native function, but you can do it with native object DateTime : calculate the duration from midnight to your time.

<?php

    $time     = new DateTime('00:00:46.70');
    $midnight = new DateTime('00:00:00.00');
    $period   = $midnight->diff($time);

    echo $period->format('T%iM%SS'); //output T0M46S

print_r($period);

Here is a php sandbox to test it