PHP code example of ramphor / date-human-readable

1. Go to this page and download the library: Download ramphor/date-human-readable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ramphor / date-human-readable example snippets




use Ramphor\Date\HumanReadable;

HumanReadable::parse(new DateTime('now'));         // Moments ago
HumanReadable::parse(new DateTime('+ 59 second')); // Seconds from now
HumanReadable::parse(new DateTime('+ 1 minute'));  // In 1 minute
HumanReadable::parse(new DateTime('- 59 minute')); // 59 minutes ago

// You can supply a secondary argument to provide an alternate reference
// DateTime. The default is the current DateTime, ie: DateTime('now'). In
// addition, it takes into account the day of each DateTime. So in the next
// two examples, even though they're only a second apart, 'Yesterday' and
// 'Tomorrow' will be displayed

$now = new DateTime('1991-05-18 00:00:00 UTC');
$dateTime = new DateTime('1991-05-17 23:59:59 UTC');
HumanReadable::parse($dateTime, $now); // Yesterday

$now = new DateTime('1991-05-17 23:59:59 UTC');
$dateTime = new DateTime('1991-05-18 00:00:00 UTC');
HumanReadable::parse($dateTime, $now) // Tomorrow