TP5 使用Db 查询在数据库中查询,一个字段是时间戳,如何在输出时转为日期?
例如将:1532311689 =》2018-07-23 10:8:9
语句如下:select *,FROM_UNIXTIME(addtime,'%Y-%m-%d %H:%i:%s') as addTime from user
重点是:FROM_UNIXTIME(addtime,'%Y-%m-%d %H:%i:%s')
---------------------
作者:nuc_八道门
来源:CSDN
原文:https://blog.csdn.net/nuc_badaomen/article/details/81976243
版权声明:本文为博主原创文章,转载请附上博文链接!
//'FROM_UNIXTIME(year,"%Y-%m-%d") as year' 将时间戳转换为日期
$need_field = ['id','title','img','origin', 'FROM_UNIXTIME(year,"%Y-%m-%d") as year'];
$news = Db::name('XXX')
->field($need_field)
->where('status','1')
->where('cat_id',$cat_id)
->where('tagid', $tagid)
->order('year','desc')
->paginate(1);