functionvalidateDate($date,$format='m-Y'){$d=DateTime::createFromFormat($format,$date);return$d&&$d->format($format)==$date;}validateDate('09-2017','m-Y');函数是从这个answer复制的或php.net我很困惑为什么它返回false而它在前几个月返回true。有什么想法吗? 最佳答案 这是因为您没有提供日期,所以它默认使用当前日期。当前日期是31日,但9月只有30天,因此会跳到10