2012-02-14 139 views
3

下面的代码...PHP,日期()不返回正确的日期/时间

$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-31 19:30:00

1969-12-31二十时30分零零秒

没有人有任何想法,为什么这不能正常工作?

+1

试试这个$ date =“2012-02-13”; – busypeoples 2012-02-14 01:58:13

+0

好问题:)。我在一次过去 – 2012-02-14 02:00:07

回答

0

看到这一点。我认为你必须改变日期格式。

$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); 
+0

这工作,我所要做的就是更换'-'以'/'和它的工作。感谢您的建议。 – 2012-04-10 05:17:23

0

您的日期格式不适合的strtotime功能

要么改变是

$date = "13-02-2012"; 

或一些其他有效的格式

0

正确,strtotime()解释为正常格式的日期,而不是美国的日期,因此它是dd-mm-yyyy

+2

“正常”迷迷糊糊是一个相对的概念 – stillstanding 2012-02-14 02:01:03

+0

@still月 - 日 - 年是*显然不正常*。 ;-P – deceze 2012-02-14 02:13:10

+0

好吧,与PHP strtotime解析器不正常有关。 :P – entropid 2012-02-14 12:47:28