时间格式转换 PHP

Time format conversion with PHP

如果食谱的持续时间格式为 1H10M(1 小时 10 分钟)或 20M(20 分钟)。我想使用括号中描述的格式。我试过使用 strtotime() 没有运气。

如有任何帮助,我们将不胜感激。

<?php
$duration="1H10M5S";
$display=str_replace(array('H','M','S'),
         array(' Hour(s) ',' Minute(s) ',' Seconds'),
         $duration);
echo $display;

输出

1 Hour(s) 10 Minute(s) 5 Seconds 

Fiddle

$yourtext = '1H10M';
$newFormat = str_replace("H", " hour,", $yourtext);
$newFormat = str_replace("M", " minutes,", $newFormat);
echo $newFormat;
$date_work = new DateTime($variable_name); $inte = $date_work->format('h:i:s');echo $inte;
<?php

function getBetween($content, $start, $end) {
    $r = explode($start, $content);
    if (isset($r[1])) {
        $r = explode($end, $r[1]);
        return $r[0];
        }
    return '';
}

$dur = "1H2M3S";

$hr = strtok($dur, "H");
$min = getBetween($dur, "H", "M");
$sec = getBetween($dur, "M", "S");

用 $hr、$min 和 $sec 做任何您想做的事。