MySQL时间戳和时间的获取/相互转换/格式化

获取当前时间戳

select unix_timestamp();

select unix_timestamp(now());

获当前时间

select now();

时间转时间戳

select unix_timestamp('2018-01-15 09:45:16');
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-01-15 09:45:16', '%Y-%m-%d');
 
世界上最美的风景,是自己努力的模样
原文地址:https://www.cnblogs.com/xiong-hua/p/13894230.html