PHP code example of joefallon / phptime

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

    

joefallon / phptime example snippets


use JoeFallon\PhpTime\Chronograph;

$timer = new Chronograph();
$timer->start();
// ... work ...
$timer->stop();

echo $timer->getElapsedMilliseconds(); // e.g. 12.3

use JoeFallon\PhpTime\MySqlDateTime;

$now = MySqlDateTime::nowTimestamp(); 
// e.g. "2025-10-13 14:05:33"

use JoeFallon\PhpTime\DaysEnum;
use JoeFallon\PhpTime\MonthsEnum;

$days = DaysEnum::all();
$months = MonthsEnum::all();

if (MonthsEnum::isValid('Feb')) { /* ... */ }

use JoeFallon\PhpTime\Chronograph;
use JoeFallon\PhpTime\SystemClock;

$clock = new SystemClock();
$chrono = new Chronograph($clock);
$chrono->start();
// ...
$chrono->stop();

echo $chrono->getElapsedMilliseconds();

use JoeFallon\PhpTime\MonthsEnum;

$all = MonthsEnum::all();        // ['January', 'February', ...]
$index = MonthsEnum::indexOf('Mar'); // 2
$name = MonthsEnum::fromIndex(11);   // 'December'

use JoeFallon\PhpTime\MySqlDateTime;

$now = MySqlDateTime::nowTimestamp();
// Insert into DB: created_at = $now

use JoeFallon\PhpTime\MySqlDateTime;
use JoeFallon\PhpTime\DateTimeProviderInterface;
use DateTimeImmutable;
use DateTimeZone;

$provider = new class implements DateTimeProviderInterface {
    public function now(): \DateTimeInterface
    {
        return new DateTimeImmutable('2001-01-02 03:04:05', new DateTimeZone('UTC'));
    }
};

MySqlDateTime::nowTimestamp($provider); // '2001-01-02 03:04:05'