MySQL時間、字符串、時間戳互相轉換

時間轉字符串
select date_format(now(), ‘%Y-%m-%d %H:%i:%s’); 
結果:2018-05-02 20:24:10
時間轉時間戳
select unix_timestamp(now()); 
結果:1525263383
字符串轉時間
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); 
結果:2018-05-02 20:16:23
時間戳轉字符串
select from_unixtime(1525263383, ‘%Y-%m’); 
結果:2018-05unix

相關文章
相關標籤/搜索