使用
mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0我有一个这样定义的表:
+-----------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| id | bigint(20) | NO | PRI | | |
| user_id | bigint(20) | NO | MUL | | |
| directory_id | bigint(20) | NO | MUL | | |
| attribute_name | varchar(255) | NO | | | |
| attribute_value | varchar(255) | YES | | NULL | |
| attribute_lower_value | varchar(255) | YES | | NULL | |
+-----------------------+--------------+------+-----+---------+-------+为我上次验证的时间选择attribute_value将返回
+-------------------+-----------------+
| attribute_name | attribute_value |
+-------------------+-----------------+
| lastAuthenticated | 1330380013284 |
+-------------------+-----------------+如果我使用http://www.epochconverter.com/验证该值,它会显示
Assuming that this timestamp is in milliseconds:
GMT: Mon, 27 Feb 2012 22:00:13 GMT但是如果我尝试下面这行代码
mysql> select from_unixtime('1330380013284');
+--------------------------------+
| from_unixtime('1330380013284') |
+--------------------------------+
| NULL |
+--------------------------------+有没有人能立刻知道我在这里错过了什么?
发布于 2012-02-28 22:01:06
你需要除以1000,同时去掉引号,否则你的日期就太远了
SELECT FROM_UNIXTIME(theField/1000);
SELECT FROM_UNIXTIME(1330380013284/1000);请参阅文档-请注意,MySQL方法返回秒,而不是您使用的毫秒:
If called with no argument, returns a Unix timestamp
(SECONDS since '1970-01-01 00:00:00' UTC) as an unsigned integer发布于 2012-02-28 21:59:48
删除',您必须传递一个数字。
https://stackoverflow.com/questions/9483205
复制相似问题