我只是好奇如何让日期函数为无效日期抛出错误。这是我尝试过的,输出在评论中。见下文:
echo date("n",strtotime("Nov"))."\n"; //outputs 11 as expected
echo date("n",strtotime("nov"))."\n"; //outputs 11 as expected
echo date("n",strtotime("dec"))."\n"; //outputs 12 as expected
echo date("n",strtotime("nova"))."\n"; //outputs 12 but instead I expected an error
是否有一个简单的函数可以用来确保文本日期有效,还是我必须滚动自己的数组来测试它?
答案 0 :(得分:0)
该函数根据PHP manual:
返回true / falseif (($timestamp = strtotime($str)) === false) {
// could not be parsed
} else {
// valid
}