MySQL中時間、時間戳和字串之間的轉換
阿新 • • 發佈:2019-01-04
涉及的函式
date_format(date,format) //時間轉換成字串
unix_timestamp() //時間或字串轉換成時間戳
str_to_date(str,format) //字串轉換成時間
from_unixtime(unix_timestamp,format) //時間戳轉換成時間或字串
一、獲取當前時間
select now();
二、獲取當前時間戳
select unix_timestamp();
select unix_timestamp(now());
三、時間轉換成時間戳
select unix_timestamp('2018-11-09 19:09:00');
四、時間戳轉換成時間
select from_unixtime(1515980716);
//時間戳格式化
select from_unixtime(1515980716,'%Y-%m-%d %H:%i:%S');
五、時間格式化
select date_format(now(),'%Y-%m-%d'); select date_format('2018-11-09 19:14:00','%Y-%m-%d');