The example in this article describes how PHP shows time in a way that has been used for a long time. Share to everyone for your reference. Specifically as follows:
Here in a more readable way to show how long it has been in the past, such as: 10 seconds from now, 1 days away from now and so on.
?
1, 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function Time_is_older_than ($t, $check _time) {$t = Strtolower ($t); $time _type = substr (preg_replace ('/[^a-z]/', ', $t), 0, 1); $val = Intval (preg_replace ('/[^0-9]/', ', ', $t)); $ts = 0; (s) econds, (m) inutes, (d) ays, (y) ears if ($time _type = = ' s ') {$ts = $val;} else if ($time _type = = ' m ') {$ts = $val * 6 0; else if ($time _type = = ' h ') {$ts = $val *) Else if ($time _type = = ' d ') {$ts = $val * *;} else if ( $time _type = = ' Y ') {$ts = $val * * * 365;} else {die (' Unknown time Format given! ');} if ($check _time < (t IME ()-$ts)) {return true; //Use Example://timestamp to test://(could is from a database or something else) $time = 1146722922; Long If Check:if (Time_is_older_than (' 30m ', $time)) {print ' The given timestamp: '. Date (' L DS of F Y h:i:s A ', $time) ; Print "-is older than minutes<br/>n"; else {print ' The given timestamp: '. Date (' L DS of F Y h:i:s A ', $time); print "-is not older than minutes<br/>n "; }//Short checks:if (Time_is_older_than (' 10s ', $time)) {print ' is older than seconds<br/>n ';} if (Time_is_olde R_than (' 200m ', $time)) {print ' is older than minutes<br/>n ';} if (Time_is_older_than (' 2h ', $time)] {print ' Is O Lder than 2 Hours<br/>n "; } if (Time_is_older_than (' 4d ', $time)) {print ' is older than 4 Days<br/>n ';} if (Time_is_older_than (' 1y ', $time)) { Print "is older than one year<br/>n"; } |
I hope this article will help you with your PHP programming.