console.log('web');|

断桥残雪丶

园龄:5年5个月粉丝:0关注:2

MySQL查询时间戳格式化 和ThinkPHP查询时间戳转换

1、mysql语句

格式化时间戳
select  id,name,FROM_UNIXTIME(time,'%Y-%m-%d %H:%i:%s') as addtime from testtable where totaltime != '';

//time是时间戳字段,查出来之后是格式化的数据 ,重命名为 addtime 
select  id,name,UNIX_TIMESTAMP(time) as addtime from testtable1;  //我的数据库存的time格式是这样的 :2019-02-27

2、thinkphp框架

格式化时间戳


$data = $model->field('id,title,FROM_UNIXTIME(time,"%Y-%m-%d %H:%i:%s") as addtime')->order('id desc')->select();

时间格式变成时间戳

$data = $model->field('id,title,UNIX_TIMESTAMP(time) as addtime')->order('id desc')->select();

本文作者:断桥残雪丶

本文链接:https://www.cnblogs.com/codexing/p/15830764.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   断桥残雪丶  阅读(346)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起