分类: MySQL

MySQL UNIX时间戳与日期的相互转换

UNIX时间戳转换为日期用函数FROM_UNIXTIME()

mysql> select FROM_UNIXTIME(1512621000);
+---------------------------+
| FROM_UNIXTIME(1512621000) |
+---------------------------+
| 2017-12-07 12:30:00       |
+---------------------------+
1 row in set (0.00 sec)

日期转换为UNIX时间戳用函数UNIX_TIMESTAMP()

mysql> Select UNIX_TIMESTAMP('2017-12-07 12:30:00');
+---------------------------------------+
| UNIX_TIMESTAMP('2017-12-07 12:30:00') |
+---------------------------------------+
|                            1512621000 |
+---------------------------------------+
1 row in set (0.00 sec)

发表新评论