Unix 时间戳和 JavaScript 时间; 太大!

发布于 2024-07-17 10:43:03 字数 595 浏览 18 评论 0原文

我正在使用 jQuery 的 flot 图形库,它对任何时间序列使用 javascript 时间(提醒一下,这是自 1970 年 1 月以来的毫秒数。Unix 时间是)。

我当前的代码如下所示:

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 或其他?

谢谢!

I'm using the flot graphing library for jQuery, and it uses javascript time for any time series (to remind, that's milliseconds since Jan 1970. Unix time is seconds).

My current code looks like this:

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

This gives me an array of Unix time stamps. I want to prep the data for JavaScript in the loop, but when I try

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

the number is too big and it spits out "[-2147483648]". Do I need to change the "type" of variable allowed to be held in the array to bignum or something?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话难免假 2024-07-24 10:43:03

试试这个:

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

这会将其转换为 float,在 php 中它可以存储比 int 更大的数字。

Try this:

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

That will turn it into float, which in php can store a bigger number than an int.

橪书 2024-07-24 10:43:03

您可以尝试使用 BCMath 任意精度函数(如果可用):

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

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

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

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

You can try using the BCMath Arbitrary Precision functions if you have them available:

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

Or just, you know, append three zeros on the end.

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

In both cases you'll end up with the value being stored as a string, but that shouldn't matter for your usage.

青瓷清茶倾城歌 2024-07-24 10:43:03

不需要解决方案,因为没有问题:让 JavaScript 执行乘法。

No solution is required, because there is no problem: have JavaScript do the multiplication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文