Create an immutable DateTime from a mutable one before PHP 5.6
suggest changeTo create a \DateTimeImmutable in PHP 5.6 and later, use:
\DateTimeImmutable::createFromMutable($mutable);
Before PHP 5.6 you can use:
\DateTimeImmutable::createFromFormat(\DateTime::ISO8601, $mutable->format(\DateTime::ISO8601), $mutable->getTimezone());
DateTime::ISO8601 drops microseconds and is not a complete ISO-8601 format.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents