Home >Backend Development >PHP Tutorial >Briefly describe the method of php outputting the time format before the specified time

Briefly describe the method of php outputting the time format before the specified time

墨辰丷
墨辰丷Original
2018-06-12 11:12:591284browse

This article mainly introduces the method of PHP outputting the time format before the specified time. It can realize the output of the specific time format before the specified time. It has certain reference value. Friends who need it can refer to the example of this article.

Describes the method of php outputting the time format before the specified time. The specific analysis is as follows:

For example, if you need to output 3 days ago and 20 minutes ago in php, you can refer to the following code

function ago($time) {
 $time = strtotime($time);
 $delta = time() - $time;
 if ($delta < 60) {
  return &#39;less than a minute ago.&#39;;
 } else if ($delta < 120) {
  return &#39;about a minute ago.&#39;;
 } else if ($delta < (45 * 60)) {
  return floor($delta / 60) . &#39; minutes ago.&#39;;
 } else if ($delta < (90 * 60)) {
  return &#39;about an hour ago.&#39;;
 } else if ($delta < (24 * 60 * 60)) {
  return &#39;about &#39; . floor($delta / 3600) . &#39; hour(s) ago.&#39;;
 } else if ($delta < (48 * 60 * 60)) {
  return &#39;1 day ago.&#39;;
 } else {
  return floor($delta / 86400) . &#39; days ago.&#39;;
 }
}

Summary: The above is this article The entire content of the article is hoped to be helpful to everyone's study.

Related recommendations:

php method to hide the actual download address of a file

php method to get the date of this Monday

phpTwo commonly used methods to recursively delete folders

The above is the detailed content of Briefly describe the method of php outputting the time format before the specified time. For more information, please follow other related articles on the PHP Chinese website!

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