PHP code example of mpratt / relativetime

1. Go to this page and download the library: Download mpratt/relativetime 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/ */

    

mpratt / relativetime example snippets


      use RelativeTime\RelativeTime;

    $relativeTime = new RelativeTime();

    $loader->registerNamespace('RelativeTime', 'path/to/RelativeTime');


    use RelativeTime\RelativeTime;

    $relativeTime = new RelativeTime();
    echo $relativeTime->convert('2010-09-05', '2010-03-30');
    // 5 months, 6 days ago

    $relativeTime = new RelativeTime();
    echo $relativeTime->convert('2012-03-05', '2013/02/05');
    // 11 months left

    use RelativeTime\RelativeTime;

    // Asumming Today is the 2013-09-23 17:23:47


    $relativeTime = new RelativeTime();
    echo $relativeTime->timeAgo('2012-08-29 06:00');
    // 1 year, 25 days, 16 hours, 23 minutes, 13 seconds ago

    $relativeTime = new RelativeTime();
    echo $relativeTime->timeLeft('2013-10-31 01:00:05');
    // 1 month, 7 days, 2 hours, 36 minutes, 52 seconds left


    use RelativeTime\RelativeTime;

    $config = array(
        'language' => '\RelativeTime\Languages\English',
        'separator' => ', ',
        'suffix' => true,
        'truncate' => 0,
        'use_weeks' => false,
    );

    $relativeTime = new RelativeTime($config);