浮动到unix时代 [英] float to unix epoch
问题描述
我从一个存储时间在unix时代的JSON数据库中提取数据,但由于某些原因,当我拔出数据时,这些数据正在浮动。这是我以前从来没有处理过的事情。所以基本上像 1293083730000
这样的数字显示为 1.293085408E + 12
我需要把数字回到历元所以我可以将它与当前时间进行比较。任何帮助将是伟大的。
这是工程符号是一种编写大量数字的方便方法。数字仍然是一个整数。
问题是,PHP的内部类型太小,不能用十进制表示数字,请看下面的例子:
<?
$ i = 1293083730000;
echo\ $ i是$ i \\\
\\\
;
echo sprintf(\ $ i是%d \\\
\\\
,$ i);
echo sprintf(\ $ i是%e \\\
\\\
,$ i);
?>
这个输出:
$ i是1293083730000
$ i是298573904
$ i是1.293084e + 12
您需要一个64位平台,或将该数字作为字符串或浮点值使用。有关更多详细信息,请参阅整数的PHP文档:
http://php.net/manual/en/language.types.integer.php
I am pulling data from an JSON database that is storing the time in unix epoch but for some reason the numbers are being floated when I'm pulling them out. This is something I've never had to deal with before. So basiclly a number like 1293083730000
is showing up as 1.293085408E+12
I need to get the number back to the epoch time so I can compare it to the current time. Any help would be great.
That's engineering notation, a convenient method of writing large numbers. The number is still an integer.
The problem is is that PHP's internal types are too small to represent the number as a decimal, see the following example:
<?
$i = 1293083730000;
echo "\$i is $i\n\n";
echo sprintf("\$i is %d\n\n", $i);
echo sprintf("\$i is %e\n\n", $i);
?>
This outputs:
$i is 1293083730000
$i is 298573904
$i is 1.293084e+12
You need either a 64-bit platform or work with the number as a string or floating point value. See the PHP documentation on Integers for more details:
http://php.net/manual/en/language.types.integer.php
这篇关于浮动到unix时代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!