2009-04-17 147 views
2

我正在使用jQuery的flot图形库,并且它为任何时间序列使用javascript时间(提醒,这是1970年1月以来的毫秒。Unix时间是)。Unix时间戳和JavaScript时间;太大!

我当前的代码如下所示:

foreach($decoded['results'] as $currentResult) { 
     if($currentResult['from_user'] == $user) { 
      $strippedTexts = $currentResult['created_at']; 
      $dates []= strtotime($strippedTexts); 
     } 
    } 

这给我的Unix时间戳的数组。我想预习的循环对JavaScript的数据,但是当我试图

$dates []= 1000*strtotime($strippedTexts); 

数量过于庞大,它吐出“[-2147483648]”。我是否需要将允许在数组中保存的变量的“类型”更改为bignum或其他?

谢谢!

+0

重复下面的评论,所以你得到一个响应通知:你如何获得的JavaScript变量? Javascript不能读取PHP变量,所以你必须以某种方式传递它。它不应该在乎在这一点上它是一个字符串还是一个数字。如果你可以展示你如何使用$ dates数组,我可以看看这个。 – 2009-04-20 04:54:44

+0

(不在我的工作电脑上),但我打印数组大致如下:,但实际使用flot库函数调用脚本标记中的变量w /。完整的计划在:http://www.phpfreaks.com/forums/index.php/topic,248668.0.html 谢谢! – 2009-04-23 18:16:03

回答

2

您可以尝试使用BCMath Arbitrary Precision functions,如果你让他们提供:

$dates[] = bcmul("1000", strtotime($strippedTexts)); 

或者只是,你知道,在末尾添加三个零。

$dates[] = strtotime($strippedTexts).'000'; 

在这两种情况下,您最终都会将值存储为字符串,但这对您的使用应该无关紧要。

+0

我试过了: $ strippedTexts = $ currentResult ['created_at']; \t \t $ bigstring = strtotime($ strippedTexts)。'000'; \t \t \t \t $ dates [] = settype($ bigstring,“float”); 它会产生所有“1”的数组。不幸的是,我正在使用的JavaScript库需要结果作为数字,而不是字符串。任何其他想法? – 2009-04-19 17:35:12

3

试试这个:

$dates []= 1000.0*strtotime($strippedTexts); 

这将变成浮动,这在PHP可以存储比int更大的数字。

0

没有解决方案是必需的,因为没有问题:JavaScript执行乘法。