我有一年(2002年),我正在尝试将其变为以下格式:
2002-00-00T00:00:00
我尝试了各种迭代,其中最后一个是:
$testdate = DateTime::createFromFormat(DateTime::ISO8601, date("c"))
echo date_format($testdate, '2002');
Run Code Online (Sandbox Code Playgroud)
但是,即使我走近了,它似乎总是在它结束时加上+00:00 ......
Mar*_*c B 13
PHP中的'c'格式总是附加时区偏移量.你无法避免这种情况.但您可以自己从组件构建日期:
date('Y-m-d\TH:i:s', $testdate);
Run Code Online (Sandbox Code Playgroud)
最好的方法是使用常量(PHP 5 >= 5.5.0,PHP 7)
date(DATE_ISO8601, $timeToChange);
Run Code Online (Sandbox Code Playgroud)
文档: http ://php.net/manual/en/class.datetimeinterface.php#datetime.constants.types