PHP code example of phplegends / timespan

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

    

phplegends / timespan example snippets


use PHPLegends\Timespan\Timespan;

$time = new Timespan(0, 0, 10);

echo $time->format(); // '00:00:10'

$time->addSeconds(30);

echo $time->format(); // '00:00:40'

$time->addSeconds(-50);

echo $time->format(); // '-00:00:10'

$time->addMinutes(2);

echo $time->format('%i minutes %s seconds');  // '1 minutes 50 seconds'


$time = Timespan::createFromFormat(
    Timespan::DEFAULT_FORMAT, 
    '26:00:00'
);

echo $time->format(); // '26:00:00'

$timespan = Timespan::createFromDateDiff(
    new DateTime('2021-01-01 23:00:00'),
    new DateTime('2021-01-03 02:00:00')
);

echo $timespan->format(); // '27:00:00'