- var_dump: documentation ( source)
- phpversion: documentation ( source)
- explode: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
- date_default_timezone_get: documentation ( source)
<?php
class MyDateTime extends DateTime
{
public static function createFromFormat($format, $time, $timezone = null)
{
$version = explode('.', phpversion());
if(!$timezone) $timezone = new DateTimeZone(date_default_timezone_get());
if(((int)$version[0] >= 5 && (int)$version[1] >= 2 && (int)$version[2] > 17)){
return parent::createFromFormat($format, $time, $timezone);
}
return new DateTime(date($format, strtotime($time)), $timezone);
}
}
$dateTime = MyDateTime::createFromFormat('Y-m-d', '2013-6-13');
var_dump($dateTime);
var_dump($dateTime->format('Y-m-d'));