PHP code example of alameda-red / datetime
1. Go to this page and download the library: Download alameda-red/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/ */
alameda-red / datetime example snippets php
$interval = new \DateInterval('P1D');
$split = DateInterval::divide($interval, 2); // \DateInterval('PT12H')
php
$interval = new \DateInterval('PT86400S');
$short = DateInterval::shorten($interval); // \DateInterval('P1D')
$short = DateInterval::shorten($interval, true); // \DateInterval('P1D')
$short = DateInterval::shorten($interval, false); // \DateInterval('PT24H')
php
$interval = new \DateInterval('PT86400S');
$string = DateInterval::getString($interval); // 'P1D'
$string = DateInterval::getString($interval, true); // 'P1D'
$string = DateInterval::getString($interval, false); // 'PT24H'
php
$interval = new \DateInterval('PT1440M');
$short = DateInterval::shortenString($interval); // 'P1D'
$short = DateInterval::shortenString($interval, true); // 'P1D'
$short = DateInterval::shortenString($interval, false); // 'PT24H'
php
$base = new \DateInterval('PT0H');
$i1 = new \DateInterval('PT1S');
$i2 = new \DateInterval('PT1M');
$i3 = new \DateInterval('PT1H');
$sum = DateInterval::sum($base, $i1, $i2, $i3); // 'PT1H1M1S'
$base = new \DateInterval('PT1H1M1S');
$i1 = new \DateInterval('PT1S'); $i1->invert = true;
$i2 = new \DateInterval('PT1M'); $i2->invert = true;
$i3 = new \DateInterval('PT1H'); $i3->invert = true;
$sum = DateInterval::sum($base, $i1, $i2, $i3); // 'PT0H', $sum->invert -> true