1、sql查询时,日期转换
DATE_FORMAT(create_time, "%Y-%m-%d") as create_time
比如:
ArticleService::getInfoById(ModelArticle::class, $id, [], [], 'id, title, content, logo, view, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
2、时间戳转日期
FROM_UNIXTIME(时间戳, "%Y-%m-%d") as time // 其中%Y-%m-%d可自定义时间格式
比如:
select ID,name,from_unixtime((timestamp + 8*3600),"%Y%-m-%d") as date
from product
where from_unixtime((timestamp + 8*3600),"%Y-%m-%d")>='2020-02-01'
3、日期转时间戳
UNIX_TIMESTAMP(时间) as time