Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the calculation of time difference by php

Shulou Source: shulou.com Published: 2022-06-01 03:24:44 09月30日 Update

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!

Tags: Differences time articles content not much most more knowledge industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology OPPO Reno Linux NVidia