Thinkphp5:[ error ] [8]A non well formed numeric value encountered报错解决方法

ThinkPHP 1221 0 2018-12-11

Thinkphp5:[ error ] [8]A non well formed numeric value encountered报错解决方法

大家一定要注意时间戳strtotime!!


数据库表字段设置 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}


上一篇:thinkphp5常用代码调用集合,建站时很实用哦

下一篇:thinkphp5+PHPMailer邮件发送配置与使用实例

讨论数量:0

请先登录再发表讨论。 2024-03-19

天涯网魂
3 杠 5 星
TA 的文章
TA 的随言
TA 的资源链