1. Basic usage: Getting a
    human readable time
  2. Using translations
  3. Generating HTML

Basic usage: Getting a human readable time difference

Just include the Date/HumanDiff.php file, instantiate a Date_HumanDiff object and run get() on it.

require_once 'Date/HumanDiff.php';
$dh = new Date_HumanDiff();
$dh->get(time() - 60) . "\n";
//prints out "5 minutes ago"

get() accepts two parameters: The timestamp and the reference time. If the reference time is not provided, the current time is used. Both parameters may be unix timestamps, DateTime objects as well as strings that can be converted to a unix timestamp with strtotime.

The difference between timestamp and reference time is then converted into a human readable string.

Date_HumanDiff (Previous) Using translations (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.