Time string to total minutes integer in PHP
Simple question, but can't find it elsewhere:
How can I transform my string of time e.g. "09:30"
into in integer containing the total minutes in that time? (Solution for "09:30"
would be 570
)
I have tried a lot of stuff, including substr
开发者_如何学Python, mktime
and strtottime
and just can't get it to work.
$time = explode(":","09:30");
$minutes = intval($time[0])*60 + intval($time[1]);
Just for reference, strtotime works as well and it may be a simpler solution.
$minutes = strtotime('09:30', 0) / 60;
Try to explode the time string (something like: explode(":","09:30")
). You can also use str_replace
. Then just simply multiply the 09
with 60 and add the 30
to it.
Hope it helps!
精彩评论