如果配方的持续时间为1H10M(1小时10分钟)或20M(20分钟)。我想使用括号中描述的格式。我没有运气就尝试使用strtotime()
。
非常感谢任何帮助。
答案 0 :(得分:3)
<?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 强>
答案 1 :(得分:0)
$yourtext = '1H10M';
$newFormat = str_replace("H", " hour,", $yourtext);
$newFormat = str_replace("M", " minutes,", $newFormat);
echo $newFormat;
答案 2 :(得分:0)
$date_work = new DateTime($variable_name); $inte = $date_work->format('h:i:s');echo $inte;
答案 3 :(得分:0)
<?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做你想做的事。