php – strtotime日期不正确
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – strtotime日期不正确,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1668字,纯文字阅读大概需要3分钟。
内容图文
![php – strtotime日期不正确](/upload/InfoBanner/zyjiaocheng/754/e2881d88fb4e4786b01a4cb8cf5312d0.jpg)
关于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,您会看到:
因此,对于日期格式(即,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无效.
此外,在User Contributed Notes部分中,note by Mirek at 2015-04-01 01:14可能有用/有趣:
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
1http://php.net/manual/en/datetime.formats.date.php
2http://php.net/manual/en/datetime.formats.date.php#Hcom117014
内容总结
以上是互联网集市为您收集整理的php – strtotime日期不正确全部内容,希望文章能够帮你解决php – strtotime日期不正确所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。