PHP code example of danielstjules / php-pretty-datetime

1. Go to this page and download the library: Download danielstjules/php-pretty-datetime 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/ */

    

danielstjules / php-pretty-datetime example snippets




use PrettyDateTime\PrettyDateTime;

PrettyDateTime::parse(new DateTime('now'));         // Moments ago
PrettyDateTime::parse(new DateTime('+ 59 second')); // Seconds from now
PrettyDateTime::parse(new DateTime('+ 1 minute'));  // In 1 minute
PrettyDateTime::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');
PrettyDateTime::parse($dateTime, $now); // Yesterday

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