第二个参数
date()必须是正确的时间戳(自1970年1月1日以来的秒数)。您正在传递一个字符串,date()无法识别。
您可以使用 strtotime()
将日期字符串转换为时间戳。但是,即使strtotime()也无法识别
y-m-d-h-i-s格式。
PHP 5.3以上
使用
DateTime::createFromFormat。它允许您使用
date()语法指定精确的掩码,以解析传入的字符串日期。
PHP 5.2及更低版本
您将必须使用手动解析元素(年,月,日,时,分,秒)
substr(),并将结果传递给
mktime(),这将为您建立一个时间戳。
但这是很多工作!我建议使用strftime()可以理解的其他格式。strftime()可理解除之外的 任何 日期输入
the next time joewill slip on the ice。例如,这有效:
$old_date = date('l, F d y h:i:s'); // returns Saturday, January 30 10 02:06:34$old_date_timestamp = strtotime($old_date);$new_date = date('Y-m-d H:i:s', $old_date_timestamp);


