PHP code example of componenta / duration

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

    

componenta / duration example snippets


use Componenta\Stdlib\Duration;

$duration = Duration::fromISO8601('PT90S');

$duration->toISO8601(); // "PT1M30S"
$duration->toSeconds(); // 90
$duration->humanize();  // "1 minute 30 seconds"

Duration::ofDays(2);
Duration::ofHours(6);
Duration::fromSeconds(3600);
Duration::between($start, $end);

$duration = Duration::ofMonths(1);

$duration->hasCalendarComponents(); // true
$duration->isFixed();               // false
$duration->toSeconds();             // throws RuntimeException
$duration->toSecondsFrom(new DateTimeImmutable('2026-01-01'));