为什么这个 strtotime 回显英语日期输入的错误输出


why is this strtotime echoing wrong output for english date input?

echo date('Y-m-d',strtotime('02-12-13'));

这是英文格式,所以

预期输出:2013-12-02

我的输出:2002-12-13

有人知道发生了什么吗?

当您指定只有两位数的年份时,strtotime 的参数将解析为yy "-" MM "-" DD格式。 请参阅 http://www.php.net/manual/en/datetime.formats.date.php(在ISO8601表示法中)。

如果您用四位数字指定年份,即 02-12-2013 ,您应该得到预期的结果。

"

xx-xx-xx"被解释为"yy-mm-dd",如手册中指定:http://www.php.net/manual/en/datetime.formats.date.php

您必须使用 date_parse_from_format () 并使用返回的数组来构建正确的格式。

http://de3.php.net/manual/en/function.date-parse-from-format.php

但是,也许最好通过简单的字符串操作来格式化原始的美国日期字符串。

使用不同的分隔符在PHP中将英国日期转换为美国日期

list($date,$month,$year) = sscanf("01/01/2012", "%d/%d/%d");
echo "$month-$date-$year";