PHP DateTime 11月Bug [英] PHP DateTime November Bug

查看:128
本文介绍了PHP DateTime 11月Bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用DateTime :: createFromFormat()正在跳过11月时遇到问题。我执行的代码是:

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');

这将持续返回2016年12月。如果我将11更改为10,则返回2016年10月,如果我更改它到12它返回2016年12月。为什么它跳过11月?

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?

推荐答案

它正在使用当月的一天,因为你没有指定一天。没有11月31日,所以它使用下一个逻辑的日子:12月1日。

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.

这篇关于PHP DateTime 11月Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆