我想將某個秒數轉換爲分鐘甚至幾小時。但我不想爲每分鐘和每小時寫一個if子句......PHP:將秒轉換爲分鐘和小時
我該如何以最簡單的方式做到這一點,並且我最簡單的意思是最短。 ;)
PHP:
$countholen = mysqli_fetch_array(mysqli_query($db, "
SELECT * FROM `blablabla` WHERE `blabla` = 'bla'
"));
$countholenfetch = $countholen["count"];
if ($countholenfetch <= 60){
$count = $countholenfetch . " sec";
}
if ($countholenfetch > 60){
$countholenfetch = $countholenfetch - 60;
$count = "1 min" . " + " . $countholenfetch . " sec";
}
//...if clause with 120, 180, 240 etc. instead of 60 till 3600 and another if clause in an if clause...
echo $count;
的可能的複製[轉換秒到小時:分鐘:秒](HTTP://計算器。 com/questions/3172332/convert-seconds-to-hourminutesecond) –
試試這個: gmdate(「H:i:s」,685); from: http://stackoverflow.com/questions/3172332/convert-seconds-to-hourminutesecond – SaidTagnit
對不起,沒有找到:(@ C.Liddell – Moritz