query about integer floating


#1

Hello,

I’m using time() to generate a timestamp, however I want it to be in milliseconds so I did the following -

$time = time()*1000;

The problem is that it’s floating the number, so coming out with the following -

$time = 1.170100744E+12

What I need is for it to be a 13 digit number, not 1.something to the power of 12.

Hope this all makes sense!I know that there is probably a really easy answer to this but I just can’t seem figure it out.

Thanks for your help.

Sian


#2

If you are using PHP 4, you can do:

[php]
list($usec, $sec) = explode(" ", microtime());
$time = ((float)$usec + (float)$sec);
[/php]

microtime() is just like time(), except that it includes the microseconds. In fact, if you are using PHP 5, it is much easier because you don’t have to combine the seconds with the microseconds. Just do:

[php]
$time = microtime(true);
[/php]

Also, when you say that the number is “coming out” showing the E+12 stuff, it will depend on how you are printing the value. You can use printf() to control how the float is shown.