![](/img/trans.png)
[英]PHP strtotime and MySQL UNIX_TIMESTAMP return different integer
[英]PHP strtotime return different value of Mysql UNIX_TIMESTAMP
我在stackoverflow上搜索过帖子,发现了一些类似的帖子。但我认为这是一个不同的帖子。
我的PHP和Mysql服务器的时区都设置为“UTC”。
在一个表中我使用了一个时间戳字段,值为“2010-11-08 02:54:15”,我使用这样的sql:
SELECT id,
updated,
second( updated ) ,
unix_timestamp( updated )
FROM `transaction`
where id = 56
明白啦:
id updated second unix
--------------------------------------------
56 2010-11-08 02:54:15 15 1289184879
然后我在php中使用它:
echo strtotime("2010-11-08 02:54:15");
明白啦:
1289184855
不同的是24秒。
我在http://www.unixtimestamp.com/index.php上查看这些时间戳.php结果是正确的。 那么mysql unix_timestamp函数有bug吗? Mysql版本是:5.1.41
这被证实是5.1.44中修复的错误。
有关详细信息,请参阅http://bugs.mysql.com/bug.php?id=51918 ,错误海报确切地发现了此问题。
你将别无选择,只能升级以避免它的外观。
我无法在Linux上的MySQL 5.1.41中重现这一点。 也许这只是Windows?
snip@ssnip:~$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 295
Server version: 5.1.41
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select unix_timestamp("2010-11-08 02:54:15");
+---------------------------------------+
| unix_timestamp("2010-11-08 02:54:15") |
+---------------------------------------+
| 1289206455 |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
maia@sloodle:~$ php -a
Interactive shell
php > echo strtotime("2010-11-08 02:54:15");
1289206455
php > exit
snip@ssnip:~$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 297
Server version: 5.1.41
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select from_unixtime(1289206455);
+---------------------------+
| from_unixtime(1289206455) |
+---------------------------+
| 2010-11-08 02:54:15 |
+---------------------------+
1 row in set (0.00 sec)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.