I believe in a number of Web sites will see a number of articles published after the article is issued in a few seconds ago or a few months ago sent the document, below I will introduce the use of PHP to calculate the time lag to calculate how long the article publication distance from now.
The code is as follows |
Copy Code |
/** * Time Difference calculation
*/ function Time2units ($time) { $year = Floor ($time/60/60/24/365); $time-= $year * 60 * 60 * 24 * 365; $month = Floor ($time/60/60/24/30); $time-= $month * 60 * 60 * 24 * 30; $week = Floor ($time/60/60/24/7); $time-= $week * 60 * 60 * 24 * 7; $day = Floor ($time/60/60/24); $time-= $day * 60 * 60 * 24; $hour = Floor ($time/60/60); $time-= $hour * 60 * 60; $minute = Floor ($time/60); $time-= $minute * 60; $second = $time; $elapse = "; $UNITARR = Array (' Year ' = ' + ' Years ', ' month ' = ' ' month ', ' Week ' = ' ' Week ', ' Day ' = ' ~ ', ' Hours ' = ' hour ', ' minutes ' = ' minute ', ' sec ' = ' second ' ); foreach ($unitArr as $CN = $u) { if ($ $u > 0) { $elapse = $ $u. $CN; Break } } return $elapse; } $past = 2052345678; Some Timestamp in the past $now = time (); Current timestamp $diff = $now-$past; Echo ' published in '. Time2units ($diff). ' former '; ?> |
http://www.bkjia.com/PHPjc/632789.html www.bkjia.com true http://www.bkjia.com/PHPjc/632789.html techarticle I believe in a number of Web sites will see a number of articles published after the article is issued in a few seconds ago or a few months ago sent documents, below I will introduce the use of PHP to calculate the time difference ...