1

如何用php转换时间?

原来的格式是这样的00:02:34 min

我需要得到一个像154. 谢谢。

4

3 回答 3

2

试试这个:

<?php
   date_default_timezone_set('GMT');
   $time = '00:00:34';
   list ($days, $hours, $minutes) = split(":", $time, 3);
   $timestamp = mktime ($hours+1, $minutes, 0, $days+1, 1, 1970, FALSE);
   $minutes = $timestamp / 60;
   print $minutes;
   print "\n";`

(编辑:date_default_timezone_set添加)

于 2010-11-11T13:27:50.397 回答
1
$myTime="00:02:34 min";
$bodytag = str_replace(" min", "", $myTime);
$myTime=explode(":",$myTime);

function timeToSeconds($hours,$minutes,$seconds){
   return $seconds+($minutes*60)+($hours*3600);
}
于 2010-11-11T13:14:23.637 回答
0

嘿 yuli chika,我建议你查看手册中的 phpdatetime函数。从那里您还可以了解字符串到时间的函数,例如,strtotime()以及mktime

日期和时间允许您指定输出格式和时间戳。格式代码的参考在我上面给出的手动链接中列出。如果您没有时间戳,则可以使用strtotime()创建一个。

于 2010-11-11T13:15:05.310 回答