版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chaoyue1861/article/details/83902184
涉及的函数
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');