Get the App
SLTechnology News&Howtos  ›  Development  › 

How to display the time in PHP as & quot; just & quot;"n minutes / hours ago & quot

Shulou Source: shulou.com Published: 2022-06-03 05:34:28 10月03日 Update

Editor to share with you how to display the time as "just" and "n minutes / hour ago" in PHP, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.

On many occasions, in order to show the timeliness of the information, the time is usually displayed as "just", "5 minutes ago", "3 hours ago", etc., instead of printing the time directly. For example, Weibo and SNS applications use this feature for the longest time. Generally, the format of the time stored in the database is Unix timestamp, so a PHP function that converts Unix timestamp into timeline display is recorded here.

The function is relatively simple, and it is easy to understand by looking directly at the code.

The code is as follows:

Note that the parameter $time in the function transfer_time () must be a Unix timestamp. If not, convert it to a Unix timestamp with strtotime () first.

The above is all the contents of the article "how to display the time in PHP as" just now "and" n minutes / hour ago ". 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: Time hour function article code content longest less information function parameter timeliness situation most data database more format knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Redmi Apple MariaDB