FROM_UNIXTIME
更新时间:2025-10-17
描述
将 unix 时间戳转化为对应的 time 格式。特殊情况:
- 目前支持的
unix_timestamp
范围为[0, 32536771199]
,超出范围的unix_timestamp
将会得到 NULL
语法
SQL
1FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
参数
参数 | 说明 |
---|---|
<unix_timestamp> |
unix 时间戳 |
<string_format> |
format 格式,默认为 %Y-%m-%d %H:%i:%s |
返回值
返回指定格式的日期。
举例
Plain Text
1mysql> select from_unixtime(1196440219);
2+---------------------------+
3| from_unixtime(1196440219) |
4+---------------------------+
5| 2007-12-01 00:30:19 |
6+---------------------------+
7
8mysql> select from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss');
9+--------------------------------------------------+
10| from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss') |
11+--------------------------------------------------+
12| 2007-12-01 00:30:19 |
13+--------------------------------------------------+
14
15mysql> select from_unixtime(1196440219, '%Y-%m-%d');
16+-----------------------------------------+
17| from_unixtime(1196440219, '%Y-%m-%d') |
18+-----------------------------------------+
19| 2007-12-01 |
20+-----------------------------------------+
21
22mysql> select from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s');
23+--------------------------------------------------+
24| from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s') |
25+--------------------------------------------------+
26| 2007-12-01 00:30:19 |
27+--------------------------------------------------+