How can i display seconds ago/minutes ago/with unix timestamp?

对着背影说爱祢 提交于 2020-01-11 13:01:13

问题


I need the unix timestamp - the timestamp i have. Then display the time between like on twitter.


回答1:


If you have the difference called diff:

$seconds = intval($diff) % 60;
$minutes = intval($diff/60) % 60;
$hours = intval($diff/3600) % 24;
$days = intval($diff/(3600*24));

Is this what you want ?




回答2:


Not sure what language you need it, but if it will end up in a web page, you may try timeago.




回答3:


Use example :

echo time_elapsed_string('@1367367755');
echo time_elapsed_string('@1367367755', true);

Output :

4 months ago
4 months, 2 weeks, 3 days, 1 hour, 49 minutes, 15 seconds ago

Link to the function.



来源:https://stackoverflow.com/questions/2822144/how-can-i-display-seconds-ago-minutes-ago-with-unix-timestamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!