문제

How to convert time with php?

the original format was like 00:02:34 min.

I need to get a echo like 154. Thanks.

도움이 되었습니까?

해결책

Try this:

<?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";`

(edit: date_default_timezone_set added)

다른 팁

$myTime="00:02:34 min";
$bodytag = str_replace(" min", "", $myTime);
$myTime=explode(":",$myTime);

function timeToSeconds($hours,$minutes,$seconds){
   return $seconds+($minutes*60)+($hours*3600);
}

Hey yuli chika, I'll suggest you check out php's date and time functions in the manual. From there you can also learn about string to time functions like, well, strtotime() and mktime;

Date and time allow you to specify a format and a timestamp for output. The reference for the format codes are listed in the manual links I gave above. If you don't have a timestamp, you can use strtotime() to create one.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top