PHP mktime突然过去了?

PHP mktime suddenly in the past?

我有一个包含这一行的脚本:

$showdate = mktime(18, 59, 0, 08, 02, 2015);

应该将变量设置为 1438556340(日期为 2015 年 8 月 2 日 6:59pm)

但是,出于某些疯狂的原因,截至今天上午,它将变量设置为 1417564740(2014 年 12 月 2 日)。

就脚本而言,数周内没有任何变化。那么为什么会突然发生变化呢?有什么办法可以解决吗?

谢谢!

正如 Sami Kuhmonen 在问题的第一条评论中指出的那样,当您指的是 8(十进制)时,您不应该使用 08 (invalid octal literal)。

<?php
echo mktime(18, 59, 0, 08, 02, 2015), "\r\n";
echo mktime(18, 59, 0, 8, 2, 2015), "\r\n";

echo 8, "\r\n";
echo 08, "\r\n";

打印

1417543140
1438534740
8
0

08 被解析为八进制数

To use octal notation, precede the number with a 0 (zero).

08 不是八进制的所以 returns 0

octal : 0[0-7]+

mktime 在文档中有以下内容

month The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s).

所以它是去年 12 月

http://php.net/manual/en/language.types.integer.php

http://php.net/manual/en/function.mktime.php