PHP code example of reply / microtime

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

    

reply / microtime example snippets




use Reply\Microtime\Microtime;

// Creates a Microtime object from current timestamp
$microtime = Microtime::fromNow();

// Creates a Microtime object from a string containing seconds and microseconds
$microtime = Microtime::fromString('0.34497500 1589445224');
// or
$microtime = Microtime::fromMicrotime('0.34497500 1589445224');

// Creates a new Microtime object from an integer containing the microseconds since the unix epoch
$microtime = Microtime::fromInt(1589445224344975);
// or
$microtime = Microtime::fromMicroseconds(1589445224344975);

// Creates a new Microtime object from a float containing the result of the microtime(true) function
$microtime = Microtime::fromFloat(1589445622.7431);

// Creates a new Microtime object from an integer containing the seconds since the unix epoch
$microtime = Microtime::fromSeconds(1589445622);

// Creates a new Microtime object from a DateTime object
$microtime = Microtime::fromDateTime(new \DateTime());

// Returns the microtime as string
$string = $microtime->toString();
// or
$string = (string) $microtime;
// or
$string = "Time in microseconds: $microtime";

// Returns the microtime as integer
$int = $microtime->toInt();

// Returns the microtime as float
$float = $microtime->toFloat();

// Returns the microtime as string in the format of the microtime() function
$string = $microtime->toMicrotime();

// Returns the microtime in a DateTime object
$dateTime = $microtime->toDateTime();

// Returns the microtime in a DateTimeImmutable object
$dateTimeImmutable = $microtime->toDateTimeImmutable();