Конвертировать микровремя PHP в миллисекунды (мс) – методы и примеры

Чтобы преобразовать микровремя PHP в миллисекунды (мс), вы можете использовать следующие методы:

Метод 1: использование функций microtimeи explode

// Get the current microtime
$microtime = microtime(true);
// Split the microtime into seconds and microseconds
list($seconds, $microseconds) = explode(' ', $microtime);
// Convert the microseconds to milliseconds
$milliseconds = round($microseconds * 1000);
// Output the result
echo $milliseconds;

Метод 2: использование функций microtimeи sprintf

// Get the current microtime
$microtime = microtime(true);
// Convert the microtime to milliseconds using sprintf
$milliseconds = sprintf("%d", $microtime * 1000);
// Output the result
echo $milliseconds;

Метод 3: использование функций microtimeи intval

// Get the current microtime
$microtime = microtime(true);
// Convert the microtime to milliseconds using intval
$milliseconds = intval($microtime * 1000);
// Output the result
echo $milliseconds;