PHP: How to echo remaining time in minutes from microtime



There are sixty (60) seconds in one (1) minute. To convert seconds to minutes, simply divide the amount of seconds by sixty (60).

$tstart = (string) microtime(true); // casting to string shows type doesn't matter
sleep(3); // for variance
$tstop = microtime(true);
$diffSeconds = round($tstop-$tstart);
$diffMinutes = ceil($diffSeconds/60); // here is the division

echo $diffSeconds.'second'.($diffSeconds==1?'':'s')."\n"; // assuming plain text out
echo $diffMinutes.'minute'.($diffMinutes==1?'':'s')."\n";


in seconds: 3.0001471042633

in minutes: 0.050002451737722

People are also looking for solutions to the problem: php - Formatting in a json decoding


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.