PHP code example of webignition / readable-duration
1. Go to this page and download the library: Download webignition/readable-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/ */
webignition / readable-duration example snippets
use webignition\ReadableDuration\Factory;
/**
* 100000 seconds is 1 day, 3 hours, 46 minutes and 40 seconds
*/
$factory = new Factory();
$readableDuration = $factory->create(100000);
$readableDuration->getDays();
// 1
$readableDuration->getHours();
// 3
$readableDuration->getMinutes();
// 46
$readableDuration->getSeconds();
// 40
use webignition\ReadableDuration\Factory;
/**
* 100000 seconds as years, months, days, hours, minute or seconds
*
* Note: these are human-readable convenience representations not exact
*
* 100000 seconds is strictly 1.16 days. As far as convenience is concerned, that's 1 day.
* 100000 seconds is strictly 27.78 hours. As far as convenience is concerned, that's 28 hours.
*/
$factory = new Factory();
$readableDuration = $factory->create(100000);
$readableDuration->getInYears();
// 0
$readableDuration->getInMonths();
// 0
$readableDuration->getInDays();
// 1
$readableDuration->getInHours();
// 28
$readableDuration->getInMinutes();
// 1667
$readableDuration->getInSeconds();
// 100000
use webignition\ReadableDuration\Factory;
/**
* 100000 seconds:
*
* - represented as a single time unit is 1 day
* - represented as two time units is 1 day 4 hours
* - represented as three time units is 1 day 3 hours 47 minutes
*
*/
$factory = new Factory();
$readableDuration = $factory->create(100000);
/**
* 100000 seconds, as a single time unit is 1 day
*/
$this->factory->getInMostAppropriateUnits($readableDuration);
// [
// [
// 'unit' => 'day',
// 'value' => 1
// ]
// ]
/**
* 100000 seconds, as two time units is 1 day 4 hours
*/
$this->factory->getInMostAppropriateUnits($readableDuration, 2);
// [
// [
// 'unit' => 'day',
// 'value' => 1
// ],
// [
// 'unit' => 'hour',
// 'value' => 4
// ]
// ]
/**
* 100000 seconds, as three time units is 1 day 3 hours 47 minutes
*/
$this->factory->getInMostAppropriateUnits($readableDuration, 3);
// [
// [
// 'unit' => 'day',
// 'value' => 1
// ],
// [
// 'unit' => 'hour',
// 'value' => 3
// ],
// [
// 'unit' => 'minute',
// 'value' => 47
// ]
// ]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.