<?php
class MyDateTime {
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: Cannot use "parent" when current class scope has no parent in /in/BSohB on line 27
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Cannot use "parent" when current class scope has no parent in /in/BSohB on line 27
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)
object(DateTime)#1 (0) {
}
string(10) "2013-06-13"
Fatal error: Call to undefined method DateTime::getTimestamp() in /in/BSohB on line 34
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/BSohB on line 21
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function strptime() in /in/BSohB on line 8
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/BSohB 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/BSohB 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/BSohB on line 3
Process exited with code 255.