Convert timestamp to hours and minutes for a movie

2020-08-04 04:58发布

I have converted the length of the movie Avatar from 2009, from minutes to timestamp. The movie is 162 minutes long so the timestamp is 1386227800. Now I need to convert the timestamp to hours and minutes which I don't know how.

In short: how can I convert a timestamp and get the correct result in hours and minutes?

I have tested floor(1386227800 / 60), date('H:i', mktime(0, 1386227800) and some functions that converts a timestamp to hours and minutes, but these only converts the hours to something endless, like 12375 or something like that.

So, how can I accomplish this?

标签: php timestamp
4条回答
祖国的老花朵
2楼-- · 2020-08-04 05:04

As one of the commenters mentioned, a timestamp represents a single point in time, not a duration. There's no reason to call strtotime at all -- if you already have the total minutes, you can ignore converting it to a timestamp and just get that into hours:minutes like this:

$time=162;

$hours = floor($time / 60);
$minutes = ($time % 60);

echo $hours.":".$minutes;
查看更多
霸刀☆藐视天下
3楼-- · 2020-08-04 05:04
echo date('H:i:s', 1386227800);
查看更多
欢心
4楼-- · 2020-08-04 05:12

Can you try,

 echo date('H:i','1386227800');
查看更多
5楼-- · 2020-08-04 05:22

As I understand it, you want to convert 162 minutes to be represented with hours and minutes. This is a simple case of mathematics.

<?php

$minutes = 162 % 60;
$hours = floor(162 / 60);

?>

$hours will return 2, and $minutes will return 42. 2 hours, 42 minutes is equivalent to 162 minutes.

Hope this helps.

查看更多
登录 后发表回答