php time()不正确,php – strtotime日期不正确

关于strtotime(),我发现了一些奇怪的东西.

在不存在的日期,它返回第二天.

$d30= strtotime("2017-06-30");

Echo $d30 ."\n";

Echo date("Y-m-d", $d30)."\n\n"; // 2017-06-30

$d31= strtotime("2017-06-31");

Echo $d31 ."\n";

Echo date("Y-m-d", $d31)."\n\n"; // 2017-07-01

$d32= strtotime("2017-06-32");

Echo $d32 ."\n";

Echo date("Y-m-d", $d32); // 1970-01-01

我理解最后一个.它没有返回任何内容,因为它是一个错误.

但为什么第二个会在7月1日之前回归?

它是否意味着功能性,如果你犯了错误,它会“纠正你”?或者它是strtotime()中的真正错误?

解决方法:

如果您查看strtotime()的文档,您将看到第一个参数是:

time

A date/time string. Valid formats are explained in 07001.

如果您按照日期和时间格式的链接进行操作,请转到Date Formats,您会看到:

rm1z5.jpg

因此,对于日期格式(即,DD),01-31是有效的(因为3只能跟随0或1),尽管是月份.根据提供的月份和日期值,将调整日期.

也可以在同一页面上的说明中找到:

Note:

It is possible to over- and underflow the dd and DD format. Day 0 means the last day of previous month, whereas overflows count into the next month. This makes “2008-08-00” equivalent to “2008-07-31” and “2008-06-31” equivalent to “2008-07-01” (June only has 30 days).07004

因此06-31有效而06-32无效.

Note: the day (dd or DD) is first checked for range 0..31 and only if it fits, the overflow and underflow mechanism may apply. If not, strtotime() simply returns false.

If you need unlimited over/underflow for date calculations (for example 2015-01-40 to 2015-02-09), use 07007 instead.07008

标签:php,strtotime

来源: https://codeday.me/bug/20190722/1501311.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值