1.mysql获取当前时间戳
mysql> select UNIX_TIMESTAMP();
+------------------+
| UNIX_TIMESTAMP() |
+------------------+
| 1525739078 |
+------------------+
1 row in set
mysql> SELECT UNIX_TIMESTAMP(NOW());
+-----------------------+
| UNIX_TIMESTAMP(NOW()) |
+-----------------------+
| 1525739117 |
+-----------------------+
1 row in set
这两个是等价的
2.mysql日期转换成时间戳
日期转换时间戳用的也是上面1所用到的函数
mysql> SELECT UNIX_TIMESTAMP('2018-05-08 08:26:30');
+---------------------------------------+
| UNIX_TIMESTAMP('2018-05-08 08:26:30') |
+---------------------------------------+
| 1525739190 |
+---------------------------------------+
1 row in set
1中的now()函数,返回当前时间的长日期,和2018-05-08 08:26:30格式相同
3.时间戳转换成日期
select FROM_UNIXTIME(1525740032);
+---------------------------+
| FROM_UNIXTIME(1525740032) |
+---------------------------+
| 2018-05-08 08:40:32 |
+---------------------------+