3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function convertUnixTimeBetweenTimezones($vUnixTime,$vOriginalTimezone,$vDesiredTimezone) { $oBaseTimeZone = new DateTimeZone($vOriginalTimezone); // user time zone $oCurrentTimeZone = new DateTimeZone($vDesiredTimezone); $oBaseTime = new DateTime("@{$vUnixTime}"); $oBaseTime->setTimezone($oBaseTimeZone); $vTimeStamp = $oBaseTime->getTimestamp(); $target = new DateTime("@{$vTimeStamp}"); $target->setTimezone($oCurrentTimeZone); return $target->getTimestamp(); } echo convertUnixTimeBetweenTimezones(1414710000,"EST","UTC"); ?>
based on TPep2
Output for 5.3.0 - 7.2.0
1414710000
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::getTimestamp() in /in/eZMSi on line 12
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTimeZone' not found in /in/eZMSi on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetimezone in /in/eZMSi on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetimezone in /in/eZMSi on line 5