---
title: "mysql 获取系统时间"
author: "不念书的小子"
date: "2011-06-11T12:29:29Z"
tags: ["MySQL", "Unix"]
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2011-06-11T12:29:29Z"
id: 1076067
url: "https://tompig.iteye.com/blog/1076067"
---

mysql&gt; select   now();  
+---------------------+  
| now()               |  
+---------------------+  
| 2011-06-11 12:00:54 |  
+---------------------+  
1 row in set (0.00 sec)

 

 

mysql&gt; select   sysdate();  
+---------------------+  
| sysdate()           |  
+---------------------+  
| 2011-06-11 12:00:54 |  
+---------------------+  
1 row in set (0.00 sec)

 

 

mysql&gt; select   curdate();  
+------------+  
| curdate()  |  
+------------+  
| 2011-06-11 |  
+------------+  
1 row in set (0.00 sec)

 

 

mysql&gt;  select   current\_date;  
+--------------+  
| current\_date |  
+--------------+  
| 2011-06-11   |  
+--------------+  
1 row in set (0.00 sec)

 

 

mysql&gt;  select   curtime();  
+-----------+  
| curtime() |  
+-----------+  
| 12:00:54  |  
+-----------+  
1 row in set (0.00 sec)

 

 

 

mysql&gt; select   current\_time;  
+--------------+  
| current\_time |  
+--------------+  
| 12:00:54     |  
+--------------+  
1 row in set (0.00 sec)

 

2\. mysql （unix 时间戳、日期）转换函数：

unix\_timestamp(),  
unix\_timestamp(date),  
from\_unixtime(unix\_timestamp),  
from\_unixtime(unix\_timestamp,format)

下面是示例：

select unix\_timestamp(); -- 1218290027 ===得到当前时间的unix时间值

将具体时间来转换成timestamp

select unix\_timestamp('2008-08-08'); -- 1218124800  
select unix\_timestamp('2008-08-08 12:30:00'); -- 1218169800

将timestamp来转换成具体时间  
select from\_unixtime(1218290027); -- '2008-08-09 21:53:47'  
select from\_unixtime(1218124800); -- '2008-08-08 00:00:00'  
select from\_unixtime(1218169800); -- '2008-08-08 12:30:00'

select from\_unixtime(1218169800, '%y %d %m %h:%i:%s %x'); -- '2008 8th august 12:30:00 2008'