3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new DateTimeImmutable('2021-03-18 14:38:45.008455'); $time = (float) $obj->format('U.u'); $recreated = DateTimeImmutable::createFromFormat('U.u', (string) $time); var_dump($obj, $recreated, $recreated == $obj); $time = json_decode($obj->format('U.u')); $recreated = DateTimeImmutable::createFromFormat('U.u', (string) $time); var_dump($obj, $recreated, $recreated == $obj);
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(false)

preferences:
69.88 ms | 535 KiB | 14 Q