我的 MySQL 将日期时间戳存储在 GMT 中,尽管服务器的时间是 EST。在添加到 MySQL 之前,我将我的日期时间转换为本地(服务器的日期时间 EST),但它存储它 GMt 而不是 EST。这里有什么问题?
item.update_attributes({:request_datetime => Time.parse(date+" "+time+" "+timezone).localtime}) # this becomes EST
puts Time.parse(date+" "+time+" "+timezone).localtime.to_s # prints correct time zone, EST.
mysql> SELECT request_datetime,NOW(),TIMESTAMPDIFF(MINUTE,request_datetime,NOW()) FROM items Where item='2542';
+---------------------+---------------------+----------------------------------------------+
| request_datetime | NOW() | TIMESTAMPDIFF(MINUTE,request_datetime,NOW()) |
+---------------------+---------------------+----------------------------------------------+
| 2012-05-05 22:30:02 | 2012-05-05 18:30:05 | -239 |
+---------------------+---------------------+----------------------------------------------+
1 row in set (0.00 sec)
mysql>