3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('UTC'); $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 ROSkb
Output for 5.5.10 - 5.6.28, 7.0.0 - 7.1.0
Original timestamp: 1414802161 UTC to EST modified Timestamp: 1414802161 EST to UTC modified Timestamp: 1414820161 PST to EST modified Timestamp: 1414830961
Output for hhvm-3.10.0 - 3.12.0
Original timestamp: 1414802161 UTC to EST modified Timestamp: 1414802161 EST to UTC modified Timestamp: 1414820161 PST to EST modified Timestamp: 1414827361
Output for 5.3.0 - 5.5.9
Original timestamp: 1414802161 UTC to EST modified Timestamp: 1414802161 EST to UTC modified Timestamp: 1414816561 PST to EST modified Timestamp: 1414827361
Output for 5.2.0 - 5.2.17
Original timestamp: 1414802161 Fatal error: Call to undefined method DateTime::getTimestamp() in /in/JhoW3 on line 19
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Original timestamp: 1414802161 Fatal error: Class 'DateTimeZone' not found in /in/JhoW3 on line 11
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/JhoW3 on line 2
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: date_default_timezone_set() in /in/JhoW3 on line 2
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: date_default_timezone_set() in /in/JhoW3 on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: date_default_timezone_set() in /in/JhoW3 on line 2