将负日期转换为DateTime get me false
测试代码
var_dump('DateTime::createFromFormat('DateTime::ISO8601, '-0001-11-30T00:00:00+0100'));
结果
boolean false
预期的结果
object(DateTime)[5]
public 'date' => string '-0001-11-30 00:00:00' (length=20)
public 'timezone_type' => int 1
public 'timezone' => string '+01:00' (length=6)
(或类似)
注:使用$d->format('DateTime::ISO8601);
创建负日期字符串PHP版本PHP 5.4.28根据格式手册
public string DateTime::format ( string $format )
,
$format
Format accepted by date().
如果你看date()
$d->format('DateTime::ISO8601);
应该$d->format("c")
因为"c"根据date()
中的格式ISO 8601日期(PHP 5新增)
在我的测试$d->format('DateTime::ISO8601);
输出
2015 - 09 - 15 t00:00:00 + 0200
,
$d->format("c");
输出2015 - 09 - 15 - t00:00:00 + 02:00