leading 0 in month parameter making wrong output

筅森魡賤 提交于 2020-01-10 06:06:07

问题


Why the leading zero in the month parameter making wrong output?

echo date("Y-m-d", mktime(0, 0, 0, 09, 23, 2013));//output 2012-12-23
echo date("Y-m-d", mktime(0, 0, 0, 9, 23, 2013));//output 2013-09-23

回答1:


From https://bugs.php.net/bug.php?id=55327:

Numbers with leading 0's are octal. 08 is an invalid value. See http://php.net/integer

If you prefix a number with a leading 0, it marks the number as Octal. The octal numeral system uses the digits 0 to 7. So, 08 and 09 doesn't exist and are invalid.

The second statement is correct, and that's the correct method:

echo date("Y-m-d", mktime(0, 0, 0, 9, 23, 2013));



回答2:


We can make this parameter as a string and it will work.

Try this:

echo date("Y-m-d", mktime(0, 0, 0, '09', 23, 2013));//output 2012-12-23


来源:https://stackoverflow.com/questions/19160334/leading-0-in-month-parameter-making-wrong-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!