php, date() 未返回正确的日期/时间
下面的代码...
$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 20:30:00
有谁知道为什么这不能正常工作?
The code below...
$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);
Returns...
1969-12-31 19:30:00
1969-12-31 20:30:00
Does anyone have any idea why this is not working correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
02-13-2012 17:30
不是可识别的日期格式。使用日-月-年或年-月-日顺序,或者使用自定义解析日期格式,例如DateTime::createFromFormat
。02-13-2012 17:30
is not a recognized date format. Either use day-month-year or year-month-day order, or custom parse the date format using, for example,DateTime::createFromFormat
.看到这个。我认为你必须更改日期格式。
See this. I think you have to change the date format.
您的日期格式对于 strtotime 函数不正确,
要么更改为
或更改为其他有效格式
your date format is not correct for strtotime function
either change is to
or to some other valid format
当您将日期格式化为
xx-yy-zzz
时,strtotime()
会将其解释为正常格式的日期,而不是美国格式的日期,因此它是dd -mm-yyyy
。When you format your date like
xx-yy-zzz
,strtotime()
interprets it as a date in the normal format, not the American one, so it'sdd-mm-yyyy
.