MySQL时--时间戳--字符串互相转换

MySQL时--时间戳--字符串互相转换

时间转时间戳

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

时间戳转时间

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

时间转字符串

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

字符串转时间

select str_to_date(‘2018-05-02’, ‘%Y-%m-%d %H’); 
结果:2018-05-02 00:00:00

字符串转时间戳

select unix_timestamp(‘2018-05-02’); 
结果:1525263383

时间戳转字符串

select from_unixtime(1525263383, ‘%Y-%m’); 
结果:2018-05

你可能感兴趣的:(MySQL时--时间戳--字符串互相转换)