我想格式化从数据库(01:00:00)检索的时间,如下所示:
01 Hrs 00 Mins 00 Secs
但是以下尝试没有奏效并且给我错误,所以我的问题是如何才能获得上述时间所需的格式:
<strong>Start Date:</strong> <?php echo date("H"),"Hrs",date("i"),"Mins",date("s"),"Secs",strtotime($detailsSessionDuration)); ?>
错误:
Parse error: syntax error, unexpected ')', expecting ',' or ';'
答案 0 :(得分:5)
尝试使用DateTime :: createFromFormat:
$d = DateTime::createFromFormat('H:i:s', '12:34:56');
echo $d->format('H \H\r\s i \M\i\n\s s \S\e\c\s');
或者您只能使用支持24 hour notation
DateTime::__construct()的time format:
$d = new DateTime('12:34:56');
echo $d->format('H \H\r\s i \M\i\n\s s \S\e\c\s');
答案 1 :(得分:2)
也许:
<strong>Start Date:</strong>
<?php
$time = strtotime($detailsSessionDuration);
echo date("H", $time),"Hrs",date("i", $time),"Mins",date("s", $time),"Secs";
?>
答案 2 :(得分:1)
$arr = explode(':', $detailsSessionDuration);
printf("%s Hrs %s Mins %s Secs", $arr[0], $arr[1], $arr[2]);