php格式日期ISO8601?
问题描述:
我有一年(2002年),我试图将其转换成以下格式:
I have a year (2002) and I'm trying to get it into the following format:
2002-00-00T00:00:00
2002-00-00T00:00:00
我尝试过各种迭代,最后一个是这样的:
I tried various iterations, the last of which was this:
$testdate = DateTime::createFromFormat(DateTime::ISO8601, date("c"))
echo date_format($testdate, '2002');
但是,即使我接近,它总是似乎添加+00:00到它...
But, even if I come close, it always seems to add +00:00 to the end of it...
答
PHP中的'c'格式总是附加时区偏移。你不能避免。但是您可以从组件中自行构建日期:
The 'c' format in PHP always appends the timezone offset. You can't avoid that. But you can build the date yourself from components:
date('Y-m-d\TH:i:s', $testdate);