How to realize the calculation of time difference by php
Editor to share with you how php to achieve time difference calculation, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Time difference calculation
Function ago ($time) {$periods = array ("second", "minute", "hour", "day", "week", "month", "year", "decade"); $lengths = array ("60", "60", "24", "7", "4.35", "12", "10"); $now = time (); $difference = $now-$time; $tense = "ago"; for ($j = 0; $difference > = $lengths [$j] & & $j < count ($lengths)-1 $difference +) {$difference / = $lengths [$j];} $difference = round ($difference); if ($difference! = 1) {$periods [$j]. = "s";} return "$difference $periods [$j] 'ago'";} above is all the content of the article "how php implements time difference calculation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!