PHP,日期()不返回正确的日期/时间
下面的代码...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分零零秒
没有人有任何想法,为什么这不能正常工作?
看到这一点。我认为你必须改变日期格式。
$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);
这工作,我所要做的就是更换'-'以'/'和它的工作。感谢您的建议。 – 2012-04-10 05:17:23
02-13-2012 17:30
不是recognized date format。无论是使用日 - 月 - 年或年 - 月 - 日顺序,或自定义解析使用的日期格式,例如,DateTime::createFromFormat
。当您格式化你的约会像xx-yy-zzz
您的日期格式不适合的strtotime功能
要么改变是
$date = "13-02-2012";
或一些其他有效的格式
正确,strtotime()
解释为正常格式的日期,而不是美国的日期,因此它是dd-mm-yyyy
。
“正常”迷迷糊糊是一个相对的概念 – stillstanding 2012-02-14 02:01:03
@still月 - 日 - 年是*显然不正常*。 ;-P – deceze 2012-02-14 02:13:10
好吧,与PHP strtotime解析器不正常有关。 :P – entropid 2012-02-14 12:47:28
试试这个$ date =“2012-02-13”; – busypeoples 2012-02-14 01:58:13
好问题:)。我在一次过去 – 2012-02-14 02:00:07