可能重複:
Output is in seconds. convert to hh:mm:ss format in php
How can i display seconds ago/minutes ago/with unix timestamp?如何將秒數轉換爲分鐘,php?
我有這樣的用戶在線腳本我的工作。到目前爲止,這是如下...
while ($online_user = $q -> fetch(PDO::FETCH_ASSOC)) {
$last_active = time() - $online_user['online'];
echo '<p>' . $online_user['username'] . ' was last active ' . $last_active . ' seconds
ago.</p>';
}
$ online_user [「在線」]是最後一次()的用戶是活躍在網站上。所以當我從當前時間減去它()後,它給了我上一次活動的秒數。
事情是在一分鐘之回聲是這樣的:
Some username was last active 567 seconds ago.
我想知道我怎麼可以把它呼應所以它會代替其轉換爲分鐘和秒所以它會是這個樣子;
Some username was last active 9 minutes and 27 seconds ago.
在此先感謝,如果你知道的任何地方我可以學習這個,請張貼鏈接。 :)
查找到PHP的'日期()'' –
日期()'是不是當它涉及到的時間差非常可靠的。如果差異超過24小時,則不起作用,或者如果差異超過一小時,則不起作用。 – JJJ