<?php
<?php
class MyDateTime extends DateTime
{
public static function createFromFormat($format, $time, $timezone = null)
{
if(!$timezone) $timezone = new DateTimeZone(date_default_timezone_get());
$version = explode('.', phpversion());
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'));
$inputDate = "wrz 2013 2 12:00:00:000";
$polishMonths = array("sty", "lut", "mar", "kwi", "maj", "cze", "lip", "sie", "wrz", "paz", "lis", "gru");
$englishMonths = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$r2pDate = str_replace($polishMonths, $englishMonths, $inputDate);
$dateTime = MyDateTime::createFromFormat('M Y j H:i:s:u', $r2pDate);
var_dump($dateTime);
var_dump($dateTime->format('Y-m-d H:i:s'));
- Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.19
- Parse error: syntax error, unexpected '<' in /in/L2DRF on line 2
Process exited with code 255.
preferences:
182.52 ms | 1395 KiB | 55 Q