0

我想格式化从数据库(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 ';'

4

3 回答 3

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');

或者您可以仅使用支持时间格式的DateTime::__construct()24 hour notation

$d = new DateTime('12:34:56');
echo $d->format('H \H\r\s i \M\i\n\s s \S\e\c\s');
于 2013-01-18T23:30:35.533 回答
2

也许:

<strong>Start Date:</strong> 
<?php 

    $time = strtotime($detailsSessionDuration);
    echo date("H", $time),"Hrs",date("i", $time),"Mins",date("s", $time),"Secs"; 
?>
于 2013-01-18T23:31:14.833 回答
1
$arr = explode(':', $detailsSessionDuration);
printf("%s Hrs %s Mins %s Secs", $arr[0], $arr[1], $arr[2]);
于 2013-01-18T23:37:04.157 回答