私には1年(2002年)があり、それを次の形式にしようとしています。
2002-00-00T00:00:00
私はさまざまな反復を試みましたが、最後はこれでした:
$testdate = DateTime::createFromFormat(DateTime::ISO8601, date("c"))
echo date_format($testdate, '2002');
しかし、私が近づいても、それは常にそれの終わりに+00:00を追加するようです...
PHP の 'c' 形式には、常にタイムゾーン オフセットが追加されます。それを避けることはできません。ただし、コンポーネントから自分で日付を作成できます。
date('Y-m-d\TH:i:s', $testdate);
問題は、多くの場合、 4 または 8の最終段階にあるミリ秒と最終のマイクロ秒で何度も発生します。DATE を ISO 8601 "date(DATE_ISO8601)"に変換するには、これらは私にとって有効なソリューションの 1 つです。
// In this form it leaves the date as it is without taking the current date as a reference
$dt = new DateTime();
echo $dt->format('Y-m-d\TH:i:s.').substr($dt->format('u'),0,3).'Z';
// return-> 2020-05-14T13:35:55.191Z
// In this form it takes the reference of the current date
echo date('Y-m-d\TH:i:s'.substr((string)microtime(), 1, 4).'\Z');
return-> 2020-05-14T13:35:55.191Z
// Various examples:
$date_in = '2020-05-25 22:12 03.056';
$dt = new DateTime($date_in);
echo $dt->format('Y-m-d\TH:i:s.').substr($dt->format('u'),0,3).'Z';
// return-> 2020-05-25T22:12:03.056Z
//In this form it takes the reference of the current date
echo date('Y-m-d\TH:i:s'.substr((string)microtime(), 1, 4).'\Z',strtotime($date_in));
// return-> 2020-05-25T14:22:05.188Z