簡體   English   中英

PHP strtotime返回Mysql UNIX_TIMESTAMP的不同值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM