3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(-1); date_default_timezone_set('Europe/Berlin'); function convertToTimestamp($str) { echo "Input: " . $str . "<br>"; $str = trim($str); // date_create(), date_fromat() ab PHP 5.2.0 if (function_exists('date_create') && function_exists('date_format')) { $date = date_create($str); $x = ($date !== false) ? (int)date_format($date, 'U') : false; echo "date_create()"; var_dump( $x ); echo "Entspricht: " . date("Y-m-d H:i", $x); echo "<p><hr></p>"; return; } // Fallback mit strtotime() $ts = strtotime($str); if ($ts == -1) $ts = false; // vor PHP 5.1 kommt -1 bei Fehler echo "strtotoime()"; var_dump($ts); echo "Entspricht: " . date("Y-m-d H:i", $ts); echo "<p><hr></p>\n"; } convertToTimestamp("2012-01-01"); convertToTimestamp("2012-01-01 15:00"); convertToTimestamp("2011-02-29"); convertToTimestamp("foo"); ?>
Output for 5.2.6 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Input: 2012-01-01<br>date_create()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p>Input: 2012-01-01 15:00<br>date_create()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p>Input: 2011-02-29<br>date_create()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p>Input: foo<br>date_create()bool(false) Entspricht: 1970-01-01 01:00<p><hr></p>
Output for 5.2.0 - 5.2.5
Input: 2012-01-01<br>date_create()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p>Input: 2012-01-01 15:00<br>date_create()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p>Input: 2011-02-29<br>date_create()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p>Input: foo<br> Warning: date_create(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database in /in/0gVml on line 13 date_create()int(1346585564) Entspricht: 2012-09-02 13:32<p><hr></p>
Output for 5.1.0 - 5.1.6
Input: 2012-01-01<br>strtotoime()int(1325372400) Entspricht: 2012-01-01 00:00<p><hr></p> Input: 2012-01-01 15:00<br>strtotoime()int(1325426400) Entspricht: 2012-01-01 15:00<p><hr></p> Input: 2011-02-29<br>strtotoime()int(1298934000) Entspricht: 2011-03-01 00:00<p><hr></p> Input: foo<br>strtotoime()bool(false) Entspricht: 1970-01-01 01:00<p><hr></p>
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/0gVml on line 4
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/0gVml on line 4
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/0gVml on line 4
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/0gVml on line 4