Core PHP

Microsecond Time String

This program demonstrates how to get the microsecond time as a string in a piece of code in PHP.

MicrosecondString.php

<?php
  // The current time string in microseconds, split into seconds and fractions
  $sCurrentTime = microtime();
  echo "Direct: ".$sCurrentTime;
  echo "<br />print_r: ";
  print_r($sCurrentTime);
  echo "<br />var_dump: ";
  var_dump($sCurrentTime);
  echo "<br />Converted To Float: ";
  list($sFraction, $sSecond) = explode(" ", $sCurrentTime);
  echo ((float)$sSecond + (float)$sFraction);
  echo "<br />Note: The float precision may cause rounding if the precision is too low.";
?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.