3v4l.org

run code in 300+ PHP versions simultaneously
<?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"); ?>

preferences:
51.17 ms | 402 KiB | 5 Q