写作时:
echo date('H:i:s', strtotime('Mar-29-2016')) . "<br />";
echo date('H:i:s', strtotime('Apr-3-2016'));我希望能得到:
00:00:00
00:00:00但实际上:
00:00:00
16:16:00改为:
echo date('H:i:s', strtotime('March 29 2016')) . "<br />";
echo date('H:i:s', strtotime('April 3 2016'));按预期工作,输出:
00:00:00
00:00:00那我不明白吗?
发布于 2016-04-04 20:21:46
尝试:
echo date('H:i:s', strtotime('Apr-03-2016'));strtotime函数希望得到一个包含英语日期格式的字符串,并尝试将该格式解析为Unix时间戳。
发布于 2016-04-04 20:28:07
“4月3日-2016年”不是有效的PHP复合日期/时间字符串。将您的字符串转换为strtotime()可以识别的内容。例如,将下面的第一个结果(您的字符串)与其他一些选项进行比较:
echo date('r', strtotime('Apr-3-2016')) . "\n";
echo date('r', strtotime('3-Apr-2016')) . "\n";
echo date('r', strtotime('2016-04-03')) . "\n";
echo date('r', strtotime('4/3/2016')) . "\n";
Sun, 03 Apr 2016 16:16:00 -0400
Sun, 03 Apr 2016 00:00:00 -0400
Sun, 03 Apr 2016 00:00:00 -0400
Sun, 03 Apr 2016 00:00:00 -0400将您的“4月3日-2016年”格式转换为“3月-4月-2016年”,例如:
$date = "Apr-3-2016";
list($m, $d, $y) = explode("-", $date);
$newdate = join("-", array($d, $m, $y));发布于 2016-04-04 20:27:25
Apr-3-2016似乎不是一种有效的日期格式。来自php文档
Month abbreviation, day and year M "-" DD "-" y "May-09-78", "Apr-17-1790"https://stackoverflow.com/questions/36412142
复制相似问题