The remaining time is when an article is published to now for a few minutes or a few days, this in many blog forums to see the article published 1 days ago, below I introduce two instances
Convert two date-formatted strings to UNIX timestamps, then subtract to get timestamp difference. To determine the time remaining, generate a format like this (2 hours, 30 minutes, 20 seconds ago)
code as follows |
copy code |
Public function gettime ($time _s, $time _ N) { $time _s = strtotime ($time _s); $time _n = strtotime ($time _n); $strtime = '; $time = $time _n-$time _s; if ($time >= 86400) { Return $strtime = Date (' y-m-d h:i:s ', $time _s); } if ($time >= 3600) { $strtime. = Intval ($time/3600). ' Hours '; $time = $time% 3600; }else{ $strtime. = '; } if ($time >=) { $strtime. = Intval ($time/60). ' Minutes '; $time = $time% 60; }else{ $strtime. = '; } if ($time > 0) { $strtime. = Intval ($time). ' Seconds ago '; }else{ $strtime = "Time error"; } Return $strtime; } |
First judge if you want to reduce the value is greater than the number of seconds in a day 86,400 seconds, if it is greater than the original database query time
Then determine if it is within 1 hours to a day, that is, 3,600 seconds-86,400 seconds, and if so, return x hours. After obtaining the result, we need to use the remainder method to remove the time of the hourly part, and use the% to take the surplus
Then determine if it is within 1 minutes to an hour, that is, 60 seconds-3,600 seconds, and if so, return x minutes. After obtaining the result, we need to use the remainder method to remove the minute part time, and use the% take-over
Finally determine whether within 1 minutes, that is, 0 seconds-60 seconds, if it is within the words will return x seconds
Note: The results above are used. = Connected. This will finally get a whole time.
http://www.bkjia.com/PHPjc/632724.html www.bkjia.com true http://www.bkjia.com/PHPjc/632724.html techarticle The remaining time is when an article is published to now have a few minutes or a few days, this in many blog forum to see the article 1 days ago released, below I introduce two instances of two ...