如何在 Windows 32 位 PHP 上将(字符串)时间戳转换为 mysql 日期时间?

发布于 2024-10-09 21:55:46 字数 511 浏览 0 评论 0原文

我正在尝试调用 LinkedIn 的 API 并存储网络更新。每个更新都有一个 Unix 时间戳,我将其作为字符串变量从 REST XML 响应中检索。

我想将字符串时间戳转换为 mysql 日期时间格式。 date() 函数接受一个整数作为要转换的时间的第二个参数。但是,我使用的是 Windows 32 位 PHP,该平台的整数类型仅限于 2147483647。

$timestamp = '1293714626675';  // sample pulled from linkedin
$timestamp = (int) $timestamp; // timestamp now equals 2147483647     
$mysqlDatetime = date('Y-m-d H:i:s', $timestamp);  // produces incorrect time

是否有更好的方法在 PHP 中创建 mysql 日期时间?我意识到我可以在插入 MySQL 时对其进行转换,但这需要更改其他相关代码。

I'm attempting to call LinkedIn's API and store Network Updates. Each update has a Unix timestamp that I'm retrieving as a string variable from the REST XML response.

I want to convert the string timestamp to a mysql datetime format. The date() function accepts an integer as the second argument for time to be converted. However, I'm on Windows 32 bit PHP and the integer type for this platform is limited to 2147483647.

$timestamp = '1293714626675';  // sample pulled from linkedin
$timestamp = (int) $timestamp; // timestamp now equals 2147483647     
$mysqlDatetime = date('Y-m-d H:i:s', $timestamp);  // produces incorrect time

Is there a better method of creating the mysql datetime in PHP? I realize that I can convert it upon insert into MySQL however, that would require changing other dependent code.

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

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

发布评论

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

评论(2

在风中等你 2024-10-16 21:55:46

您的时间戳是 UNIX 纪元的秒。将该数字除以 1000,您应该会得到正确的结果。

Your timestamp is micro seconds from UNIX epoch. Divide that number by 1000 an you should get the correct result.

怪我鬧 2024-10-16 21:55:46

试试这个:

$date = '1293714626675';
print_r(date_parse_from_format("U", $date));

另请检查 http://www.php.net/manual/en/datetime.createfromformat .php

Try this:

$date = '1293714626675';
print_r(date_parse_from_format("U", $date));

also check http://www.php.net/manual/en/datetime.createfromformat.php

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