FROM_UNIXTIME
描述
将 unix 时间戳转化为对应的 time 格式。
备注
自 3.0.8 与 3.1.0 起,unix_timestamp
的输入范围为 [0, 253402271999.999999]
,超出范围的值将返回 NULL
。
将 unix 时间戳转化为对应的 time 格式。特殊情况:
- 目前支持的
unix_timestamp
范围为[0, 32536771199]
,超出范围的unix_timestamp
将会得到 NULL
语法
FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
参数
参数 | 说明 |
---|---|
<unix_timestamp> | unix 时间戳 |
<string_format> | format 格式,默认为 %Y-%m-%d %H:%i:%s |
返回值
返回指定格式的日期。
举例
mysql> select from_unixtime(1196440219);
+---------------------------+
| from_unixtime(1196440219) |
+---------------------------+
| 2007-12-01 00:30:19 |
+---------------------------+
mysql> select from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss');
+--------------------------------------------------+
| from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss') |
+--------------------------------------------------+
| 2007-12-01 00:30:19 |
+--------------------------------------------------+
mysql> select from_unixtime(1196440219, '%Y-%m-%d');
+-----------------------------------------+
| from_unixtime(1196440219, '%Y-%m-%d') |
+-----------------------------------------+
| 2007-12-01 |
+-----------------------------------------+
mysql> select from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s');
+--------------------------------------------------+
| from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s') |
+--------------------------------------------------+
| 2007-12-01 00:30:19 |
+--------------------------------------------------+
新行为示例(自 3.0.8 与 3.1.0 起)
以下示例展示了 3.0.8/3.1.0 及之后版本扩展后的上限。在此之前,相同输入会返回 NULL。
-- 3.0.8/3.1.0+ 的最大支持时间
mysql> select from_unixtime(253402271999.999999);
+------------------------------------+
| from_unixtime(253402271999.999999) |
+------------------------------------+
| 9999-12-31 23:59:59.999999 |
+------------------------------------+