我将此代码插入timestamp
到mySql数据库(i need to this for customize
)中:
$datepub = $_POST['datepub'];
$timepub = $_POST['timepub'];
$timedate = $datepub .''.$timepub;
$datetime = DateTime::createFromFormat('Y/m/d h:i:s', $timedate);
$month = $datetime->format('m'); // Line 61
$year = $datetime->format('Y');
$date = $datetime->format('d');
$hour = $datetime->format('h');
$minute = $datetime->format('i');
$sec = $datetime->format('s');
但是我看到了这个错误:
Fatal error: Call to a member function format() on a non-object in C:\xampp\htdocs\cms\modules\add.php on line 61
当我echo $timedate
输出时:2014/03/1516:45:30
我该如何解决此错误?
答案 0 :(得分:1)
纠正如下:
$timedate = $datepub .' '.$timepub;//add a space
$datetime = DateTime::createFromFormat('Y/m/d H:i:s', $timedate); //need capital H
干杯,
答案 1 :(得分:0)
你错过了一个空白区域。这一行:
$timedate = $datepub .''.$timepub;
应该是:
$timedate = $datepub . ' ' . $timepub;