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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM