MySQL——sql语句处理时间——时间、字符串、时间戳互相转换

时间——>字符串

select date_format(now(), '%Y-%m-%d %H:%i:%s');
-- 结果:2018-05-02 20:24:10

时间——>时间戳

select unix_timestamp(now());
-- 结果:1525263383

时间戳——>字符串

select from_unixtime(1525263383, '%Y-%m-%d %H:%i:%s');
-- 结果:2018-05-02 20:24:10

时间戳——>时间

select from_unixtime(1525263383);
-- 结果:2018-05-02 20:16:23

字符串——>时间

select str_to_date('2018-05-02','%Y-%m-%d %H:%i:%s');
-- 结果:2018-05-02 06:03:21

字符串——>时间戳

select unix_timestamp('2018-05-02 20:24:10');
-- 结果:1525263383
原文地址:https://www.cnblogs.com/zuiyue_jing/p/12769486.html