3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createDtFromTimestamp(float $timestamp): \DateTime { $timestamp = round($timestamp * 1e6) * 1e-6; $sec = (int) sprintf('%0.0f', floor($timestamp)); $usec = (int) sprintf('%0.0f', min(max(($timestamp - $sec) * 1e6, 0), 999999)); $datetime = new \DateTime(date('Y-m-d H:i:s.', $sec) . sprintf('%06d', $usec)); return $datetime; } function dumpDt(\DateTime $dt) { echo $dt->format('Y-m-d H:i:s.u') . ' ' . $dt->getTimestamp() . ' ' . $dt->format('u') . "\n"; } foreach ([0.4, 0, -0.4, -1, -1.4] as $ts) { $dateExpected = createDtFromTimestamp($ts); dumpDt($dateExpected); $date = new DateTime('@' . $ts); dumpDt($date); echo "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
1970-01-01 01:00:00.400000 0 400000 1970-01-01 00:00:00.400000 0 400000 1970-01-01 01:00:00.000000 0 000000 1970-01-01 00:00:00.000000 0 000000 1970-01-01 00:59:59.600000 -1 600000 1969-12-31 23:59:59.600000 -1 600000 1970-01-01 00:59:59.000000 -1 000000 1969-12-31 23:59:59.000000 -1 000000 1970-01-01 00:59:58.600000 -2 600000 1969-12-31 23:59:58.600000 -2 600000

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
25.25 ms | 406 KiB | 5 Q