UNIX_TIMESTAMP
更新时间:2025-10-17
unix_timestamp
描述
语法
INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
将 Date 或者 Datetime 类型转化为 unix 时间戳。
如果没有参数,则是将当前的时间转化为时间戳。
参数需要是 Date 或者 Datetime 类型。
对于在 1970-01-01 00:00:00 之前或 2038-01-19 03:14:07 之后的时间,该函数将返回 0。
Format 的格式请参阅 date_format
函数的格式说明。
该函数受时区影响。
举例
Plain Text
1mysql> select unix_timestamp();
2+------------------+
3| unix_timestamp() |
4+------------------+
5| 1558589570 |
6+------------------+
7
8mysql> select unix_timestamp('2007-11-30 10:30:19');
9+---------------------------------------+
10| unix_timestamp('2007-11-30 10:30:19') |
11+---------------------------------------+
12| 1196389819 |
13+---------------------------------------+
14
15mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
16+---------------------------------------+
17| unix_timestamp('2007-11-30 10:30-19') |
18+---------------------------------------+
19| 1196389819 |
20+---------------------------------------+
21
22mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
23+---------------------------------------+
24| unix_timestamp('2007-11-30 10:30%3A19') |
25+---------------------------------------+
26| 1196389819 |
27+---------------------------------------+
28
29mysql> select unix_timestamp('1969-01-01 00:00:00');
30+---------------------------------------+
31| unix_timestamp('1969-01-01 00:00:00') |
32+---------------------------------------+
33| 0 |
34+---------------------------------------+
keywords
Plain Text
1UNIX_TIMESTAMP,UNIX,TIMESTAMP