dongqiyou0303 2016-10-31 20:39
浏览 28
已采纳

PHP DateTime November Bug

I am having an issue where using DateTime::createFromFormat() is skipping November. The code I am executing is:

$dateTime = DateTime::createFromFormat('m Y', "11 2016");
return $dateTime->format('F Y');

This keeps returning December 2016. If I change the 11 to 10 it returns October 2016 and if I change it to 12 it returns December 2016. Why is it skipping November?

  • 写回答

1条回答 默认 最新

  • dongzj2015 2016-10-31 20:42
    关注

    It's using the current day of the month because you did not specify a day. There is no 31st of November so it uses the next logical day: December 1st.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?