免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5825 | 回复: 11

mysql from_unixtime 问题, 为啥一样 [复制链接]

论坛徽章:
0
发表于 2011-04-12 18:08 |显示全部楼层
  1. mysql> select from_unixtime(1289119523);select from_unixtime(1289123123);
  2. +---------------------------+
  3. | from_unixtime(1289119523) |
  4. +---------------------------+
  5. | 2010-11-07 01:45:23       |
  6. +---------------------------+
  7. 1 row in set (0.00 sec)

  8. +---------------------------+
  9. | from_unixtime(1289123123) |
  10. +---------------------------+
  11. | 2010-11-07 01:45:23       |
  12. +---------------------------+
  13. 1 row in set (0.00 sec)
复制代码

论坛徽章:
0
发表于 2011-04-13 09:57 |显示全部楼层
http://dev.mysql.com/doc/refman/ ... tion_unix-timestamp

有讲,但看不懂,谁给解释下.

论坛徽章:
0
发表于 2011-04-13 10:07 |显示全部楼层
恕我眼拙,没看出什么问题啊?

论坛徽章:
0
发表于 2011-04-13 10:34 |显示全部楼层
回复 3# TomLeng

select from_unixtime(1289119523);select from_unixtime(1289123123);

1289119523 和 1289123123 不一样,为啥结果一样.

论坛徽章:
0
发表于 2011-04-13 10:50 |显示全部楼层
本帖最后由 horizonhyg 于 2011-04-13 11:32 编辑

回复 4# quanpai


   为啥我执行就不一样呢?
  1. mysql> select from_unixtime(1289119523);select from_unixtime(1289123123);
  2. +---------------------------+
  3. | from_unixtime(1289119523) |
  4. +---------------------------+
  5. | 2010-11-07 16:45:23       |
  6. +---------------------------+
  7. 1 row in set (0.00 sec)

  8. +---------------------------+
  9. | from_unixtime(1289123123) |
  10. +---------------------------+
  11. | 2010-11-07 17:45:23       |
  12. +---------------------------+
  13. 1 row in set (0.00 sec)
复制代码
它是说在使用UNIX_TIMESTAMP() and FROM_UNIXTIME()这两个函数 做TIMESTAMP 和 Unix timestamp 转换的时候,并不是一对一的关系,
由于时区或者其他的原因,UNIX_TIMESTAMP()对两个TIMESTAMP 做转换可能产生相同的Unix timestamp值,但是用FROM_UNIXTIME()再转回去的时候,它只匹配一个TIMESTAMP 值.

论坛徽章:
0
发表于 2011-04-13 13:44 |显示全部楼层
本帖最后由 quanpai 于 2011-04-13 13:45 编辑

回复 5# horizonhyg
我也是偶然发现, 在某些机子上一样.

关键是这问题要比较哪些东西. 说是时区问题,咋看.

论坛徽章:
0
发表于 2011-04-13 15:52 |显示全部楼层
顶了.

论坛徽章:
0
发表于 2011-04-14 12:53 |显示全部楼层
root:[dev][(none)]> select from_unixtime(1289119523);select from_unixtime(1289123123);
+---------------------------+
| from_unixtime(1289119523) |
+---------------------------+
| 2010-11-07 16:45:23       |
+---------------------------+
1 row in set (0.00 sec)

+---------------------------+
| from_unixtime(1289123123) |
+---------------------------+
| 2010-11-07 17:45:23       |
+---------------------------+
1 row in set (0.01 sec)

LZ,你的时区没设置对吧?

论坛徽章:
0
发表于 2011-04-14 22:29 |显示全部楼层
root:[dev][(none)]> select from_unixtime(1289119523);select from_unixtime(1289123123);
+----------- ...
TomLeng 发表于 2011-04-14 12:53


怎么设对.

论坛徽章:
0
发表于 2011-04-15 13:03 |显示全部楼层
在RHEL可以如下操作:
system root user 执行
# system-config-date
选中Asia/Shanghai
不要选System clock uses UTC
save或ok退出
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP