3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $vUnixTime = "1414802161"; echo("Original timestamp: " . $vUnixTime . "\n"); $vOriginalTimezone = "UTC"; $vDesiredTimezone = "EST"; $oBaseTimeZone = new DateTimeZone($vOriginalTimezone); // user time zone $oCurrentTimeZone = new DateTimeZone($vDesiredTimezone); $vIsoTime = date("Y-m-d H:i:s",$vUnixTime); $oBaseTime = new DateTime($vIsoTime,$oBaseTimeZone); $oBaseTime->setTimezone($oCurrentTimeZone); echo("UTC to EST modified Timestamp: " . $oBaseTime->getTimestamp() . "\n"); $vTimeStamp = "1414802161"; $vOriginalTimezone = "EST"; $vDesiredTimezone = "UTC"; $oBaseTimeZone = new DateTimeZone($vOriginalTimezone); // user time zone $oCurrentTimeZone = new DateTimeZone($vDesiredTimezone); $vIsoTime = date("Y-m-d H:i:s",$vUnixTime); $oBaseTime = new DateTime($vIsoTime,$oBaseTimeZone); $oBaseTime->setTimezone($oCurrentTimeZone); echo("EST to UTC modified Timestamp: " . $oBaseTime->getTimestamp() . "\n"); $vOriginalTimezone = "PST"; $vDesiredTimezone = "EST"; $oBaseTimeZone = new DateTimeZone($vOriginalTimezone); // user time zone $oCurrentTimeZone = new DateTimeZone($vDesiredTimezone); $vIsoTime = date("Y-m-d H:i:s",$vUnixTime); $oBaseTime = new DateTime($vIsoTime,$oBaseTimeZone); $oBaseTime->setTimezone($oCurrentTimeZone); echo("PST to EST modified Timestamp: " . $oBaseTime->getTimestamp() . "\n"); ?>
based on lUo8N
Output for 5.5.10 - 7.1.0
Original timestamp: 1414802161 UTC to EST modified Timestamp: 1414805761 EST to UTC modified Timestamp: 1414823761 PST to EST modified Timestamp: 1414834561
Output for 5.3.0 - 5.5.9
Original timestamp: 1414802161 UTC to EST modified Timestamp: 1414805761 EST to UTC modified Timestamp: 1414820161 PST to EST modified Timestamp: 1414830961
Output for 5.2.0 - 5.2.17
Original timestamp: 1414802161 Fatal error: Call to undefined method DateTime::getTimestamp() in /in/ROSkb on line 17
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Original timestamp: 1414802161 Fatal error: Class 'DateTimeZone' not found in /in/ROSkb on line 9
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Original timestamp: 1414802161 Fatal error: Cannot instantiate non-existent class: datetimezone in /in/ROSkb on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Original timestamp: 1414802161 Fatal error: Cannot instantiate non-existent class: datetimezone in /in/ROSkb on line 9