<?php
class MyDateTime extends DateTime {
public static function createFromFormat($dformat, $dvalue) {
$schedule = $dvalue;
$schedule_format = str_replace(array('Y','m','d', 'H', 'i','a'),array('%Y','%m','%d', '%I', '%M', '%p' ) ,$dformat);
// %Y, %m and %d correspond to date()'s Y m and d.
// %I corresponds to H, %M to i and %p to a
$ugly = strptime($schedule, $schedule_format);
$ymd = sprintf(
// This is a format string that takes six total decimal
// arguments, then left-pads them with zeros to either
// 4 or 2 characters, as needed
'%04d-%02d-%02d %02d:%02d:%02d',
$ugly['tm_year'] + 1900, // This will be "111", so we need to add 1900.
$ugly['tm_mon'] + 1, // This will be the month minus one, so we add one.
$ugly['tm_mday'],
$ugly['tm_hour'],
$ugly['tm_min'],
$ugly['tm_sec']
);
$new_schedule = new DateTime($ymd);
return $new_schedule;
}
public function getTimeStamp() {
return method_exists('DateTime', 'getTimestamp') ?
parent::getTimestamp() : $this->format('U');
}
}
$dateTime = MyDateTime::createFromFormat('d/m/Y', '13/06/2013');
var_dump($dateTime);
var_dump($dateTime->format('Y-m-d'));
var_dump($dateTime->getTimeStamp());
Fatal error: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) must be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false in /in/0BehK on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) must be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) in /in/0BehK on line 3
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/0BehK on line 3
object(DateTime)#1 (3) {
["date"]=>
string(26) "2013-06-13 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Output for 7.3.32 - 7.3.33
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(26) "2013-06-13 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
string(10) "2013-06-13"
int(1371081600)
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(26) "2013-06-13 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(26) "2013-06-13 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(26) "2013-06-13 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Output for 5.4.0 - 5.4.29, 5.5.0 - 5.5.13
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(19) "2013-06-13 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Output for 5.3.0 - 5.3.29
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with that of DateTime::createFromFormat() in /in/0BehK on line 30
object(DateTime)#1 (3) {
["date"]=>
string(19) "2013-06-13 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
string(10) "2013-06-13"
int(1371074400)
Output for 5.2.0 - 5.2.17
object(DateTime)#1 (0) {
}
string(10) "2013-06-13"
Fatal error: Call to undefined method DateTime::getTimeStamp() in /in/0BehK on line 35
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/0BehK on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0BehK on line 3
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/0BehK on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/0BehK on line 3
Process exited with code 255.