ThinkPHP5显示A non well formed numeric value encountered错误的解决办法

第一种:解决办法:关闭时间戳自动转换功能。

1.全局关闭,在config.php文件中加入以下代码:

'datetime_format' = false

  

 

2.模型关闭,在对应的模型中加入以下代码:

public function getCreateTimeAttr($time)
{
    return $time;//返回create_time原始数据,不进行时间戳转换。
}

 第二种:

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

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

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

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

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

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

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

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

3.检测数据类型(不一样的使用intval()转换)