MySQL时间函数from_unixtime()date_format()unix_timestamp()now()说明
now() 当前时间
mysql> select now();
+———————+
| now() |
+———————+
| 2018-05-04 14:58:10 |
+———————+
1 row in set (0.00 sec)
unix_timestamp() 当前时间戳
mysql> select unix_timestamp();
+——————+
| unix_timestamp() |
+——————+
| 1525417093 |
+——————+
1 row in set (0.00 sec)
unix_timestamp(now()) 当前时间转换成时间戳
unix_timestamp(‘2018-01-01’) 指定时间转换成时间戳
from_unixtime() 将时间截转换为时间
date_format() 将时间转换为时间 将时间换一种格式显示
mysql> select date_format(now(), ‘%Y/%m/%d’);
+——————————–+
| date_format(now(), ‘%Y/%m/%d’) |
+——————————–+
| 2018/05/04 |
+——————————–+
1 row in set (0.00 sec)
mysql> select queuedate,date_format(queuedate, ‘%Y-%m-%d %H:%i:%s’),cdate,from_unixtime(cdate, ‘%Y-%m-%d %H:%i:%s’) from uc_queue limit 2;
+———–+———————————————+————+——————————————-+
| queuedate | date_format(queuedate, ‘%Y-%m-%d %H:%i:%s’) | cdate | from_unixtime(cdate, ‘%Y-%m-%d %H:%i:%s’) |
+———–+———————————————+————+——————————————-+
| 20160831 | 2016-08-31 00:00:00 | 1476876215 | 2016-10-19 19:23:35 |
| 20160909 | 2016-09-09 00:00:00 | 1476876218 | 2016-10-19 19:23:38 |
+———–+———————————————+————+——————————————-+