php格式日期ISO8601? [英] php - format date ISO8601?
本文介绍了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);
这篇关于php格式日期ISO8601?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文