【问题标题】:PHP strtotime return different value of Mysql UNIX_TIMESTAMPPHP strtotime 返回 Mysql UNIX_TIMESTAMP 的不同值
【发布时间】:2010-11-08 03:30:36
【问题描述】:

我在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

【问题讨论】:

  • 仅供参考,SELECT UNIX_TIMESTAMP('2010-11-08 02:54:15'); 在 MySQL 5.1.37 上给我 1289152455。
  • 我也是,@deceze,我和 OP 一样使用 MySQL 5.1.41。
  • 我无法在 5.1.49 上使用与 TIMESTAMP 或 DATETIME 相同的值进行复制。

标签: php mysql datetime


【解决方案1】:

已确认这是 5.1.44 中修复的错误。

详情请见http://bugs.mysql.com/bug.php?id=51918,bug 发帖者已经发现了这个问题。

你别无选择,只能升级以避免它的外观。

【讨论】:

  • 尽管该票证中的另一张海报说仍然有same problems in 5.1.45。很奇怪。
  • 仅针对 5.1.45 和 5.1.46 中的 windows 版本,在过去的版本中没有进一步提及此错误,因此 5.1.52 应该都很好,但测试是唯一确定的方法。
【解决方案2】:

我无法在 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)  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 2016-02-16
    • 1970-01-01
    相关资源
    最近更新 更多