3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $time = array( false, 'sdfasas', '0000-00-00', '0000-00-00 00:00:00', '1231231', '2013-03-02 02:03:03', '2014-04-21', ); function getJsonDate($unixTimestamp = null) { if (is_null($unixTimestamp)) { $unixTimestamp = time(); } return '/Date(' . ($unixTimestamp * 1000) . date('O') . ')/'; } foreach($time as $s) { $iStartTime = ((strtotime($s) >= 0) ? strtotime($s) : 0); var_dump(getJsonDate($iStartTime)); }
based on iM9OH
Output for 5.2.4 - 7.2.0
string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"
Output for 5.1.2 - 5.2.3
string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(25) "/Date(943916400000+0200)/" string(25) "/Date(943916400000+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"
Output for 5.1.0 - 5.1.1
string(26) "/Date(1430305702000+0200)/" string(14) "/Date(0+0200)/" string(25) "/Date(943916400000+0200)/" string(25) "/Date(943916400000+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"
Output for 5.0.1 - 5.0.5
Warning: strtotime(): Called with an empty time parameter. in /in/9rT27 on line 22 string(14) "/Date(0+0200)/" string(14) "/Date(0+0200)/" string(25) "/Date(943916400000+0200)/" string(25) "/Date(943916400000+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"
Output for 4.3.2 - 5.0.0
Notice: strtotime(): Called with empty time parameter in /in/9rT27 on line 22 Notice: strtotime(): Called with empty time parameter in /in/9rT27 on line 22 string(26) "/Date(1430258400000+0200)/" string(14) "/Date(0+0200)/" string(25) "/Date(943916400000+0200)/" string(25) "/Date(943916400000+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"
Output for 4.3.0 - 4.3.1
Notice: strtotime() [http://www.php.net/function.strtotime]: Called with empty time parameter in /in/9rT27 on line 22 Notice: strtotime() [http://www.php.net/function.strtotime]: Called with empty time parameter in /in/9rT27 on line 22 string(26) "/Date(1430258400000+0200)/" string(14) "/Date(0+0200)/" string(25) "/Date(943916400000+0200)/" string(25) "/Date(943916400000+0200)/" string(14) "/Date(0+0200)/" string(26) "/Date(1362186183000+0200)/" string(26) "/Date(1398031200000+0200)/"