php,date()未返回正确的日期/时间

php,date()未返回正确的日期/时间,php,date,strtotime,Php,Date,Strtotime,下面的代码 $date = "02-13-2012"; $start_time = "17:30"; $end_time = "20:00"; $start_timestamp = date("m-d-Y H:i",strtotime($date." ".$start_time)); $end_timestamp = date("m-d-Y H:i",strtotime($date." ".$end_time)); print($start_timestamp); print($end_ti

下面的代码

$date = "02-13-2012";
$start_time = "17:30";
$end_time = "20:00";

$start_timestamp = date("m-d-Y H:i",strtotime($date." ".$start_time));
$end_timestamp = date("m-d-Y H:i",strtotime($date." ".$end_time));

print($start_timestamp);
print($end_timestamp);
返回

1969-12-3119:30:00

1969-12-31 20:30:00


有人知道为什么这不能正常工作吗?

02-13-2012 17:30
不是问题。使用日-月-年或年-月-日顺序,或使用自定义解析日期格式,例如。

对于strotime函数,您的日期格式不正确

要么改变,要么改变

 $date = "13-02-2012";

或者使用其他有效格式

当您将日期格式化为
xx-yy-zzz
时,
strotime()
将其解释为正常格式的日期,而不是美国格式的日期,因此它是
dd-mm-yyy
请参见此。我想你必须改变日期格式

$date = "02-13-2012";
$date = str_replace("-","/",$date);
$start_time = "17:30";
$end_time = "20:00";

$start_timestamp = date("m-d-Y H:i",strtotime($date." ".$start_time));
$end_timestamp = date("m-d-Y H:i",strtotime($date." ".$end_time));

print($start_timestamp);
echo "<br/>";
print($end_timestamp);
$date=“02-13-2012”;
$date=str_替换(“-”、“/”、$date);
$start_time=“17:30”;
$end_time=“20:00”;
$start_timestamp=date(“m-d-Y H:i”,strotime($date.”“$start_time));
$end_timestamp=date(“m-d-Y H:i”,strotime($date.”“$end_time));
打印($start\u时间戳);
回声“
”; 打印($end_时间戳);
试试这个$date=“2012-02-13”;好问题:)。我偶然发现了它past@still月日年显然不正常-PWell,与PHP strotime解析器不相关:p这很有效,我所要做的就是用
/
替换
-
,它就起作用了。谢谢你的建议。