网站首页技术博客

报错A non well formed numeric value encountered(Thinkphp时间戳自动转换问题)​

洞天水月2021-03-12 14:29:281971人次阅读
摘要数据库表字段设置 datetime类型,渲染的时候系统会自动进行转换,datetime类型再做一次转换就出现了“A non well formed numeric value encountered”错误。或者设置了获取器,获取数据时自动进行了类型转换。这时用getData获取原始数据就可以啦

数据库表字段设置 datetime类型,渲染的时候系统会自动进行转换,datetime类型再做一次转换就出现了“A non well formed numeric value encountered”错误。或者设置了获取器,获取数据时自动进行了类型转换。这时用getData获取原始数据就可以啦

解决方法:

1、在database.php 中设置取消数据类型的自动转换:

//时间字段取出后的默认时间格式

‘datetime_format’=>false,

2、模板中格式化输出时间

{$time|strtotime|date="Y年m月d日 h时:i分:s秒",###}

$time 是日期字符串,一般后台的时间是"Y-m-d h:i:s"

strtotime()把字符串转化为时间整数

date(format, timestamp) 把整数时间timestamp按照format格式转换为字符串

"###"表示前面的变量在date函数中的传入位置

3、数据库表时间字段设置 int类型,

    模板中直接输出时间{$time}



文章评论