MySQL time, string, timestamp convert each other
Others
2022-04-22 18:30:45
views: 0
time to string
- select date_format(now(), ‘%Y-%m-%d’);
结果:2018-05-02
time to timestamp
- select unix_timestamp(now());
result: 1525263383
String to time
- select str_to_date('2018-05-02', '%Y-%m-%d %H');
result: 2018-05-02 00:00:00
String to Timestamp
- select unix_timestamp('2018-05-02');
result: 1525263383
Timestamp to time
- select from_unixtime(1525263383);
result: 2018-05-02 20:16:23
Timestamp to string
- select from_unixtime(1525263383,'%Y-%d');
result: 2018-02
Origin http://43.154.161.224:23101/article/api/json?id=325213416&siteId=291194637