我有变量$EDate,我用strtotime函数对这个变量使用不同的值,结果如下:
$EDate = 10-21-2013; echo "strtotime($EDate)"; the result = nothing and the type is boolean
$EDate = 09-02-2013; echo "strtotime($EDate)"; the result = 1360386000 and the type is integer
$EDate = 09-30-2013; echo "strtotime($EDate)"; the result = nothing and the type is boolean
$EDate = 09-30-2013; echo "strtotime($EDate)"; the result = nothing and the type is boolean
$EDate = 07-02-2014; echo "strtotime($EDate)"; the result = 1391749200 and the type is integer
$EDate = 10-12-2014; echo "strtotime($EDate)"; the result = 1418187600 and the type is integer谁能解释一下这一点,以及如何避免布尔结果?
发布于 2013-10-03 17:03:40
来自文档
通过查看各个组件之间的分隔符,可以消除m/d/y或dot格式中的日期歧义:如果分隔符是斜杠(/),则假定为美国的m/d/y;而如果分隔符为破折号(-)或点(.),则假定为欧洲的d-m-y格式,则假定为。
您的代码假定日期为d-m-y格式,并将返回FALSE,因为月份值不正确:
var_dump(strtotime('10-21-2013')); // no month 21
var_dump(strtotime('09-30-2013'));
var_dump(strtotime('09-30-2013'));如果您希望能够使用自定义格式,请使用DateTime::createFromFormat():
$date = DateTime::createFromFormat('m-d-Y', '10-21-2013');
echo $date->format('U');发布于 2013-10-03 16:58:01
编辑:这个答案不再适用于这个问题,见下面的评论。
把你的值放在引号中,这样它们就变成了字符串:
$EDate = '10-21-2013';
...您当前的代码做了一个数学减法:10-12-2013= -2015。
https://stackoverflow.com/questions/19164923
复制相似问题