By default, PHP will populate missing date values with those of the current date/time; so
$date = DateTime::createFromFormat('m/Y', '02/2017');
will populate the missing day value with the current date; and as 31st February is an invalid date, it will roll forward into March. Likewise, hours/minutes/seconds will be populated with the missing time values based on the current time.
If you want to force the behaviour of forcing to the beginning of the month/time, then modify your mask with a leading !
$date = DateTime::createFromFormat('!m/Y', '02/2017');
This will populate the missing day with the 1st of the month, and the time with 00:00:00
Alternatively, a trailing |
will have the same effect
$date = DateTime::createFromFormat('m/Y|', '02/2017');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…