it知识
MySQL如何获取当前时间和时间戳
2023-08-06 21:10  点击:0

1、获得当前日期+时间(date + time)函数:now()

MySQL> select now();
+———————+
| now() |
+———————+
| 2022-04-08 20:56:19 |
+———————+

除了now()函数能获得当前的日期时间外,MySQL 中还有下面的函数:

current_timestamp()
,current_timestamp,localtime()
,localtime
,localtimestamp — (v4.0.6)
,localtimestamp() — (v4.0.6)
MySQL 时间戳(Timestamp)函数

2、MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()

mysql> select current_timestamp, current_timestamp();
+——————————————+
| current_timestamp | current_timestamp() |
+——————————————+
| 2008-08-09 23:22:24 | 2008-08-09 23:22:24 |
+——————————————+