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-05


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM