简体   繁体   中英

Showing time elapsed with php

我想显示自博客或类似的时间发布以来所经过的时间,我使用的是php,我将时间存储为unix时间戳,但我无法为我的直播找出如何显示时间,因为它是使用存储的时间戳发布的。

If for example your posted timestamp is:

1289735677

You can also get the current timestamp by using time() , for example.

Then you can take your posted timestamp from the current one:

time() - 1289735677

In that way you will get the seconds elapsed. Now you can change them to human readable format for example.

See examples on how you can convert seconds to human readable format:

  1. http://www.phpro.org/examples/Convert-Seconds-To-Hours-Minutes-Seconds-Words.html

  2. http://www.laughing-buddha.net/php/lib/sec2hms/

如果你的PHP> = 5.3.0,你可以使用DateTime :: diff方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM