MySQL UNIX时间戳与日期之间切换

比如:
2010-11-11 11:11:11 的UNIX时间戳为 1289473895

假如你要在操作中要对其中一种切换成另一种

主要用到了两个函数:UNIX_TIMESTAMP, FROM_UNIXTIME

2010-11-11 11:11:11 —> 1289473895
UNIX_TIMESTAMP(‘2010-11-11 11:11:11’) 显示出来的就是 1289473895

1289473895 —> 2010-11-11 11:11:11
FROM_UNIXTIME(1289473895) 显示出来的就是 2010-11-11 11:11:11

例:

mysql> select unix_timestamp('2010-11-11 11:11:11');
+---------------------------------------+
| unix_timestamp('2010-11-11 11:11:11') |
+---------------------------------------+
|                            1289473895 |
+---------------------------------------+
1 row in set (0.00 sec)
 
mysql> select from_unixtime( 1289473895);
+----------------------------+
| from_unixtime( 1289473895) |
+----------------------------+
| 2010-11-11 11:11:11        |
+----------------------------+
1 row in set (0.00 sec)