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


数据库表字段设置 datetime类型,渲染的时候系统会自动进行转换,datetime类型再做一次转换就出现了“A non well formed numeric value encountered”错误。

解决方法:

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}



猜你喜欢

转载自blog.csdn.net/u012767761/article/details/80197630