PHP code example of magicspacepanda / time-duration
1. Go to this page and download the library: Download magicspacepanda/time-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/ */
magicspacepanda / time-duration example snippets
use MagicSpacePanda\TimeDuration;
// Handles durations as a float (1 hour and 45 minutes)
$floatTime = TimeDuration::createFromNumeric(1.75);
printf("Time spend on project is %s", $floatTime);
// Handles durations as an integer (3 hours)
$intTime = TimeDuration::createFromNumeric(1);
printf("Time spend on project is %s", $intTime);
// Handles durations as a string (5 hours and 25 minutes)
$strTime = TimeDuration::createFromString('5h 25m');
printf("Time spend on project is %s", $strTime);
// Convert output to DateTime instance
$floatTime->toDateTime();
// Convert output to custom format
$intTime->toFormat('H:i');
// Convert output to machine-friendly milliseconds
$strTime->toMilliseconds();