-3

To get the microseconds and timestamp, I use code from answer:

$milliseconds = round(microtime(true) * 1000);

This gives the current timestamp with microseconds, like 1528720042358.

How do I only get the microseconds part?

Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155
  • 1
    You did read the manual…? http://php.net/microtime – deceze Jun 11 '18 at 12:30
  • 1
    @IsThisJavascript The code above adds the current timestamp *with* microseconds. My aim is to only get the microseconds part with should be a value between `1-999` – Henrik Petterson Jun 11 '18 at 12:31
  • 1
    Firstly, why in the world are people downvoting this question and the answers? Secondly, I might answer my own question here with `$time = explode('.', microtime(true)); $microsec = $time[1];` – Henrik Petterson Jun 11 '18 at 12:41

1 Answers1

1

To get just the part after the decimal point, don't pass true as argument to microtime and explode on a space:

list($msec) = explode(' ', microtime());

From there multiply or round the value to whatever range you need:

echo $msec * 1000000;
deceze
  • 510,633
  • 85
  • 743
  • 889