2011-12-10 90 views

回答

2
try { 
    $date = new DateTime($textbox->getValue()); 
} cath (Exception $e) { 
    $errors[] = 'Invald date format, please use Y-m-d H:i:s'; 
} 


if (!($date instanceof DateTime)) { 
    echo 'Variable $date is not DateTime object!'; 
} 
+0

OFC你知道,你可以aprove正確的答案? :d –

+0

+1使用DateTime類 - 很好的答案。 :) –

0

如何:

function getTime($date) { 
    $timestamp = strtotime((string)$date); 
    return date("m-d-Y H:i:s", $timestamp); 
}