Home >Backend Development >PHP Tutorial >PHP implements the function code that posted information a few minutes ago

PHP implements the function code that posted information a few minutes ago

WBOY
WBOYOriginal
2016-07-25 08:59:56934browse
  1. /**
  2. * Published minutes ago
  3. * site bbs.it-home.org
  4. */
  5. function cTime($seconds){
  6. if($seconds<60){
  7. $msg=$seconds."seconds";
  8. }elseif( $seconds<3600){
  9. $msg=(int)($seconds/60)."minute";
  10. }elseif($seconds<86400){
  11. $msg=(int)($seconds/60/60). "hours";
  12. }else{
  13. $msg=(int)($seconds/60/60/24)."days";
  14. }
  15. return $msg;
  16. }
  17. ?>
Copy code

2. Calling method:

  1. $addtime = time();
  2. $seconds = $addtime - $rswy['addtime'];
  3. echo cTime($seconds);
  4. ?>
Copy code

The above is a simple example given in today's PHP tutorial. Let's give it a try for the reference of beginners.

>>>> Articles you may be interested in: PHP implements timeline function (just now, 5 minutes ago) Sample code for php to get time and how many minutes ago Small example of PHP deleting all files created N minutes ago php displays the implementation code just now, a few minutes ago, and a few hours ago according to the time



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn