In php, for example, there is the number 1.319983091E+12 (time() / 1000)
, milliseconds, the analogue of the new Date().getTime()
. Question: how to translate the number in the normal? That is, for example, 1319982493275, or another way to find out the milliseconds?
|
3 answers
microtime(1)
will microtime(1)
float
. Next, I think, figure it out)
|
<?php list($a, $b) = explode(" ", microtime()); $millis = $b * 1000 + round($a * 1000); echo $millis; // или проще: echo round(microtime(true) * 1000); ?>
- You will find the mistake yourself?) - Sh4dow
echo microtime(true);
course I would like to myself) addedecho microtime(true);
and it gave out exactly 1000 times smaller value than the previous one, which seems to be logical, because milliseconds are required. For example,1319984792547
and1319984792.5475
. - ivkremer- oneAll my joint, I admit. For some reason, I thought $ a would be an integer. And this,
round(microtime(1)*1000)
the worse?) - Sh4dow - Yes, I then thought that it would be more adequate ...) I just never recognized the millisecond myself, but used the splitting. The splitting only shows where seconds are, and where is the rest ... I added to my answer, thanks. - ivkremer
|
They write ( http://php.su/learnphp/datatypes/?integer ) that in PHP, integers are usually 32 bits long (from –2,147,483,648 to 2,147,483,647).
Therefore, time in milliseconds from 1.1.1970 as an integer cannot be represented.
- It can be extended to long ... Anyway, this number appears on the screen through
echo
. - ivkremer - round (microtime (true) * 1000) is a float 64-bit IEEE format. It is clear that there are milliseconds placed. In what format echo ( PHP stupid documentation) displays float I could not find. Apparently (if there is no fractional part (round!)) As a chain of decimal digits. - avp 4:05 pm
- PHP is mysterious ...) - ivkremer
- mda, google is no longer the same - Sergey V.
|