01/20/2011 = January 20, 2011
01/2011 = January 2011
只允许这两种格式!
i.e. 01/01/01/2011 = ERROR!
PHP:
$date = '01/20/2011';
//$date = '01/2011';
if(........format test........)//01/20/2011
{
if(...validation...)
{
echo date('F j, Y', strtotime($date));
}
}
else//01/2011
{
if(...validation...)
{
echo date('F Y', .....);
}
}
验证
IF = 01/20/2011
IF = 01/2011
答案 0 :(得分:0)
这会有效吗?
function custom_checkdate($date){
$date_parts = explode('/', $date);
if(count($date_parts) === 3){
$d = $date_parts[1];
$m = $date_parts[0];
$y = $date_parts[2];
}elseif(count($date_parts) === 2){
$d = 1;
$m = $date_parts[0];
$y = $date_parts[1];
}else{
return false;
}
if( checkdate($m, $d, $y) ){
return true;
}else{
return false;
}
}