rhe*_*lem 2 mysql timestamp unix-timestamp
运用
mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
Run Code Online (Sandbox Code Playgroud)
我有一个像这样定义的表:
+-----------------------+--------------+------+-----+---------+-------+
| 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 | |
+-----------------------+--------------+------+-----+---------+-------+
Run Code Online (Sandbox Code Playgroud)
选择我上次验证时间的attribute_value将返回
+-------------------+-----------------+
| attribute_name | attribute_value |
+-------------------+-----------------+
| lastAuthenticated | 1330380013284 |
+-------------------+-----------------+
Run Code Online (Sandbox Code Playgroud)
如果我使用http://www.epochconverter.com/验证该值,它说
Assuming that this timestamp is in milliseconds:
GMT: Mon, 27 Feb 2012 22:00:13 GMT
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试以下代码行
mysql> select from_unixtime('1330380013284');
+--------------------------------+
| from_unixtime('1330380013284') |
+--------------------------------+
| NULL |
+--------------------------------+
Run Code Online (Sandbox Code Playgroud)
有谁立刻知道我在这里缺少什么?
您需要除以1000以及删除引号,否则您的日期将被取消
SELECT FROM_UNIXTIME(theField/1000);
SELECT FROM_UNIXTIME(1330380013284/1000);
Run Code Online (Sandbox Code Playgroud)
请参阅文档 - 注意MySQL方法返回SECONDS,而不是像你使用的毫秒:
If called with no argument, returns a Unix timestamp
(SECONDS since '1970-01-01 00:00:00' UTC) as an unsigned integer
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8324 次 |
| 最近记录: |