thinkphp5出现A non well formed numeric value encountered的解决办法修改formatDateTime方法如下

默认值:
if (is_null($this->autoWriteTimestamp)) {
// 自动写入时间戳默认false 包含datetime、date、timestamp
$this->autoWriteTimestamp = $this->getQuery()->getConfig('auto_timestamp');//getConfig:获取database.php的配置参数或者convention.php下的database项
} if (is_null($this->dateFormat)) {
// 设置时间戳格式默认Y-m-d H:i:s
$this->dateFormat = $this->getQuery()->getConfig('datetime_format');
} if (is_null($this->resultSetType)) { //数据集返回类型默认array 可选collection(返回collection对象)
$this->resultSetType = $this->getQuery()->getConfig('resultset_type');
} tp获取器部分逻辑:
存在$this->createTime或者$this->updateTime的情况下
如果$this->autoWriteTimestamp的值是datetime、date、timestamp其中一种则
执行 $value = $this->formatDateTime(strtotime($value), $this->dateFormat);
否则(值为其他情况如true):
$value = $this->formatDateTime($value, $this->dateFormat); 所以要不就关闭自动更新时间 否则formatDateTime方法第一个参数可能会出现两种情况中的一种(时间戳与非时间戳)
/**
* 时间日期字段格式化处理
* @access public
* @param mixed $time 时间日期表达式
* @param mixed $format 日期格式
* @param bool $timestamp 是否进行时间戳转换
* @return mixed
*/
protected function formatDateTime($time, $format, $timestamp = false)
{
if (false !== strpos($format, '\\')) {
$time = new $format($time);
} elseif (!$timestamp && false !== $format) {# !timestamp默认false走这里 设置为date timestap datetime则不走这里
#修改开始位置
if (!preg_match("/^[0-9]{10}|[0-9]{13}$/",$time)) {
$time=strtotime($time);
}#修改结束位置
$time = date($format, $time);
}
return $time;#直接返回
}

或者在模型文件:修改

    protected $autoWriteTimestamp=false;         // 是否需要自动写入时

又或者修改datebase.php

'datetime_format' = false
datetime、date、timestamp

tp5 报 A non well formed numeric value encountered 的错解决办法的更多相关文章

  1. 安装应用程序 报“ 997 重叠 I/O 操作在进行中”错解决办法

    解决办法: 原因: Per Microsoft's blog, patch KB2918614 appears to have caused installation issues 按照微软的博客,补 ...

  2. 关于TP5模板输出时间戳问题--A non well formed numeric value encountered

    某日.因为一个项目.控制器我是这么写的 1 /** 2 * get admin/Picture/index 3 * 显示所有图册信息 4 * @return view 5 */ 6 public fu ...

  3. 关于PHP Notice: A non well formed numeric value encountered, 你知道多少

    ---------------------------------------------------------------------------------------------- A non ...

  4. A non well formed numeric value encountered

    在从数据库获取时间戳数据的时候返回的结果是varchar类型 然后在用date("Y-m-d H:i:s", 时间戳)的时候会报错A non well formed numeric ...

  5. sphinx :undefined reference to `libiconv' 报错解决办法

    sphinx :undefined reference to `libiconv' 报错解决办法   2013-11-30 21:45:39 安装sphinx时不停报错...郁闷在make时报错,错误 ...

  6. MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法

    MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法 错误2,系统找不到文件. 开始...运行... regedit  注册表项: HKEY_LOCAL_ ...

  7. spring boot jpa 使用update 报错解决办法

    在spring boot jpa 中自定义sql,执行update操作报错解决办法: 在@Query(...)上添加 @Modifying@Transactional注解

  8. Aasible中cryptography兼容性报错解决办法

    Aasible中cryptography兼容性报错解决办法 1 Ansible中使用ansible --version查看版本,报错信息如下: ERROR! Unexpected Exception, ...

  9. sysctl -P 报错解决办法

    sysctl -P 报错解决办法问题症状修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl  -P 报错error: "net.bridge.bridge ...

随机推荐

  1. <jquery>基本的模态框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. P1919 【模板】A*B Problem升级版 /// FFT模板

    题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...

  3. Nginx 教程 2:性能

    为了获得更好的学习效果,我们建议你在本机安装 Nginx 并且尝试进行实践. tcp_nodelay, tcp_nopush 和 sendfile tcp_nodelay 在 TCP 发展早期,工程师 ...

  4. 自己新机器安装CM时候 server服务启动DB配置

    com.cloudera.cmf.db.type=mysqlcom.cloudera.cmf.db.host=localhost:3306com.cloudera.cmf.db.name=cmfcom ...

  5. Arrays.asList()使用的问题

    在java语言中,把数组转换成List集合,有个很方便的方法就是 List<String> list = Arrays.asList("a","b" ...

  6. golang 高效字符串拼接

    https://blog.csdn.net/u012210379/article/details/45110705 虽然方便,但是使用+=操作符并不是在一个循环中往字符串末尾追加字符串最有效的方式,一 ...

  7. artTemplate不仅可以在浏览器中使用,还可以在node中使用

    artTemplate不仅可以在浏览器中使用,还可以在node中使用 浏览器中引入lib/template-web.js node中  var  template = require(‘art-tem ...

  8. drupal-note2 drush运行make文件

    进入durpal项目的根目录中执行 drush make build-openpublic.make /path/to/webroot 参考: Managing Drush make files fo ...

  9. 设置IDEA中properties文件显示中文

    路径: File - Setting - Editor - Code Style - File Encodings

  10. Python3基础笔记_列表

    # Python 列表(List) list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5] list3 = [&quo ...