from_unixtime, unix_timestamp

FROM_UNIXTIME(unix_timestamp)为MySQL里的时间函数。

from_unixtime 将数据库中的时间戳转换成对应的时间格式:

select count(*) from table_name where from_unixtime(time/1000,'%Y-%m-%d') bewteen
'2019-01-01' and '2019-01-02';
time 为时间戳格式

※ from_unixtime 会使time字段的索引失效。

unix_timestamp
UNIX_TIMESTAMP() 是与之相对正好相反的时间函数 。

select unix_timestamp('2018-01-01') from table_name limit 1;

将返回一个时间戳,unix_timestamp() 不会让time字段的索引失效,因而效率更高。

你可能感兴趣的:(from_unixtime, unix_timestamp)