DEV Community 👩‍💻👨‍💻

Morcos Gad
Morcos Gad

Posted on

Calculate Time with microtime() PHP - Laravel

Let's start quickly and I found something interesting. If we want according to the duration of a certain operation in seconds in laravel it is possible to use the microtime function which accepts the value of float Let's see the example

$startTime = microtime(true);

//do something...

$seconds = number_format((microtime(true) - $startTime) * 1000, 2);
echo $seconds . ' seconds'; //19.35 seconds
Enter fullscreen mode Exit fullscreen mode

I hope it helps you in some of your future projects
Source :-

Top comments (0)

Build Anything...

Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. 👀

Join the Hackathon <-