MySQL时间戳和时间格式转换函数

时间:2022-02-06 13:04:32

MySQL时间戳和时间格式转换函数:unix_timestamp and from_unixtime

unix_timestamp将时间转化成时间戳格式。
from_unixtime将时间戳转化成时间格式。

mysql> select unix_timestamp(now());
+-----------------------+
| unix_timestamp(now()) |
+-----------------------+
|            1251884321 |
+-----------------------+
1 row in set (0.00 sec)

mysql> select from_unixtime(1251884321);
+---------------------------+
| from_unixtime(1251884321) |
+---------------------------+
| 2009-09-02 17:38:41       |
+---------------------------+
1 row in set (0.00 sec)