加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php-date()方法,“遇到的非格式数值”不想格式化在$_POST中传递的日期

发布时间:2020-05-31 01:34:19 所属栏目:PHP 来源:互联网
导读:我不幸的是不能使用DateTime()作为这个项目正在运行 PHP v.5.2的服务器. 有问题的行: $aptnDate2 = date(Y-m-d, $_POST[nextAppointmentDate]); 引发以下错误: Notice: A non well formed numeric value encountered 所以我的var转储,以确保它格式很好.. va

我不幸的是不能使用DateTime()作为这个项目正在运行 PHP v.5.2的服务器.

有问题的行:

$aptnDate2 = date('Y-m-d',$_POST['nextAppointmentDate']);

引发以下错误:

Notice: A non well formed numeric value encountered

所以我的var转储,以确保它格式很好..

var_dump($_POST['nextAppointmentDate']);  

string(10) "12-16-2013"

php docs state它需要一个时间戳不是一个字符串.但是当我做:

date('Y-m-d',strtotime($_POST['nextAppointmentDate']));

然后var_dump结果,我得到这个:

string(10) "1969-12-31"

为什么我不能使用此日期值和strtotime()格式化日期?

谢谢!

strtotime()的文档:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/),then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.),then the European d-m-y format is assumed.

在你的日期字符串中,你有12-16-2013. 16不是有效的月份,因此strtotime()返回false.

由于您不能使用DateTime类,您可以手动替换 – with / using str_replace()将日期字符串转换为strtotime()了解的格式:

$date = '2-16-2013';
echo date('Y-m-d',strtotime(str_replace('-','/',$date))); // => 2013-02-16

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读