Human readable time formats means that the date of a post or comment is displayed as “x time ago”. This format is much easier to read and interpret, and gives the reader a “relative sense” of when the item was published.
I have been using the human readable time format in my recent widget tutorials, so I thought I’d put out this quick tip on how you can do it as well.
We are going to use three different functions to achieve the desired effect:
- human_time_diff() – determines difference between two times and returns in human readable format
- get_the_time() – returns the publication time of the current post
- current_time() – returns the current time of the server
The final code that will display our human readable time is:
echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; |
This will display something like: “2 days ago”.