我正在尝试调用LinkedIn的API并存储网络更新。每次更新都有一个Unix时间戳,我将它作为字符串变量从REST XML响应中检索出来。
我想将字符串timestamp转换为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,然而,这将需要更改其他相关代码。
发布于 2010-12-30 23:54:23
您的时间戳是从UNIX纪元开始的微秒。将这个数字除以1000,你就会得到正确的结果。
发布于 2010-12-31 04:43:28
试试这个:
$date = '1293714626675';print_r(date_parse_from_format("U",$date));
另请检查http://www.php.net/manual/en/datetime.createfromformat.php
https://stackoverflow.com/questions/4564023
复制相似问题