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 时将其转换,但这需要更改其他相关代码。

4

2 回答 2

3

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

于 2010-12-30T15:54:23.460 回答
0

试试这个:

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

还要检查http://www.php.net/manual/en/datetime.createfromformat.php

于 2010-12-30T20:43:28.383 回答