PHP code example of weblabormx / easy-time

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

    

weblabormx / easy-time example snippets


use WeblaborMX\EasyTime\EasyTime;

$time = EasyTime::createFromSeconds(20465);
$time = EasyTime::createFromFormat('10:30:00'); // HH:ii:ss
$time = EasyTime::createFromFormat('32:10'); // ii:ss
$time = EasyTime::createFromFormat('2:10:30:00'); // With days
$time = EasyTime::create(0, 10, 30, 00); // Days, Hours, Minutes, Seconds
// Parse = createFromFormat
$time = EasyTime::parse('10:30:00'); // HH:ii:ss
$time = EasyTime::parse('32:10'); // ii:ss
$time = EasyTime::parse('2:10:30:00'); // With days

$time = EasyTime::createFromFormat('2:10:30:00');
$time->second; 		// 0
$time->getSeconds(); 	// 210600 (Total seconds in all that time)
$time->minute; 		// 30
$time->getMinutes(); 	// 3510 (Total minutes in all that time)
$time->hour; 		// 10
$time->getHours(); 	// 58.5 (Total hours in all that time)
$time->day; 		// 2
$time->getDays(); 	// 2.42 (Total days in all that time)
$time->format(); 	// '58:30:00'
$time->format('full'); 	// '2:10:30:00'
$time->format('short'); // '30:00'

// First way
$sum = EasyTime::sum('00:30:30', '01:03:05');	// 01:33:35

// Second Way
$time = EasyTime::createFromFormat('00:30:30');
$time2 = EasyTime::createFromFormat('01:03:05');
$time = $time->addTime($time2); 	// 01:33:35

// First way
$sum = EasyTime::rest('02:30:30', '01:03:05');	// 01:27:25

// Second Way
$time = EasyTime::createFromFormat('02:30:30');
$time2 = EasyTime::createFromFormat('01:03:05');
$time = $time->subTime($time2); 	// 01:27:25

$time = EasyTime::createFromFormat('00:30:30');
$time = $time->addSeconds(5);		// 0:00:30:35
$time = $time->addSecond();		// 0:00:30:36
$time = $time->addMinutes(6);		// 0:00:36:36
$time = $time->addMinute();		// 0:00:37:36
$time = $time->addHours(2);		// 0:02:37:36
$time = $time->addHour(); 		// 0:03:37:36
$time = $time->addDays(2);		// 2:03:37:36
$time = $time->addDay();		// 3:03:37:36
$time = $time->subDays(2);		// 1:03:37:36
$time = $time->subDay();		// 0:03:37:36
$time = $time->subHours(2);		// 0:01:37:36
$time = $time->subHour();		// 0:00:37:36
$time = $time->subMinutes(6);		// 0:00:31:36
$time = $time->subMinute();		// 0:00:30:36
$time = $time->subSeconds(5);		// 0:00:30:31
$time = $time->subSecond();		// 0:00:30:30

$time = EasyTime::createFromFormat('00:30:31');
$time = $time->multiply(2); 		// 01:01:02
$time = $time->divide(2); 		// 00:30:31

$time = EasyTime::createFromFormat('00:30:31');
$time = $time->multiply(10.5); 		// 05:20:26
$time = $time->divide(2); 		// 02:40:13

$time = EasyTime::createFromFormat('2:10:30:00');
$time->diffForHumans(); // 2 days, 10 hours, 30 minutes

$time = EasyTime::createFromFormat('00:30:02');
$time->diffForHumans(); // 30 minutes

$time = EasyTime::createFromFormat('02:10:32');
$time->diffForHumans(); // 2 hours, 10 minutes

$time = EasyTime::createFromFormat('01:01:32');
$time->diffForHumans(); // 1 hour, 1 minute

$time = EasyTime::createFromFormat('2:10:30:00');
$time->diffForHumans('en'); // 2 days, 10 hours, 30 minutes
$time->diffForHumans('es'); // 2 días, 10 horas, 30 minutos

'es' => [
    'days' => 'días',
    'day' => 'día',
    'minutes' => 'minutos',
    'minute' => 'minuto',
    'hours' => 'horas',
    'hour' => 'hora',
]