strtotime on incorrect dates

后端 未结 2 1252
太阳男子
太阳男子 2020-12-21 03:44

I found something odd about strtotime().

On dates that do not exist it returns the day after.

$d30= strtotime(\"2017-06-30\");
Echo $d30 .\"\\n\";
         


        
2条回答
  •  一整个雨季
    2020-12-21 04:20

    As day 31 of a month is possible strtotime() will correct the date for you. If you try it with February (2017-02-31) it will correct to 2017-03-03. This is what you found.

    So, what it essentially does is:

    1. get the date
    2. check if the date is in a valid range (days per month)
    3. if not valid count days into the next month

    This behaviour is implemented into the strtotime function itself.

    There was a great comment on the documentation page about this, but I am no longer able to find it. This comment provides some extra information (be sure to check the link in the comment).

提交回复
热议问题