2010-07-31 53 views
1
date_create('sdfsdfdsfsd') //invalid 
date_create('2010-07-30 08:03') //valid 

回答

6

你可以从documentation看到它是一个简单的DateTime::__construct别名其中:

返回一个新的DateTime实例。 程序样式在 失败时返回FALSE。

+1

+1可怕的回报“新的答案已经发布”吧...... – BoltClock 2010-07-31 13:10:04

+0

哎呀......我太慢太 – Jhong 2010-07-31 13:11:11

1

这是不是覆盖了manual page的顶部?

<?php 
$date = date_create('2000-01-01'); 
if (!$date) { 
    $e = date_get_last_errors(); 
    foreach ($e['errors'] as $error) { 
     echo "$error\n"; 
    } 
    exit(1); 
} 

echo date_format($date, 'Y-m-d'); 
?> 
+0

或: '尝试{$ d = new DateTime('blargh !!!');} catch(Exception $ e){echo $ e-> getMessage();}' – SeanJA 2010-07-31 13:11:22