php strtotime一周前出错


php strtotime one week ago wrong?

我需要获得一周前的毫秒数。

我试过这个:

$this->weekDate = strtotime("-1 week");
echo($this->weekDate);

它返回:

1422536434

根据该转换工具:http://www.fileformat.info/tip/java/date2millis.htm是

Samstag, 17. Januar 1970 11:08 Uhr GMT

有人知道怎么了吗?

上面的代码以秒为单位打印时间使用下面的代码

$this->weekDate = strtotime("-1 week");
echo($this->weekDate * 1000);

上述代码的输出将是

1,422,536,434,000

希望这能帮助您

这可能是因为时区的原因(您在1周前尝试计算时没有提到,所以很难判断您期望的输出)。

试试这个:

//get current time
$now = time();
//output in human readable format
echo 'now: ' . date('r', $now) . '<br />';
//calculate same time 1 week ago
$this->weekDate = strtotime("-1 week", $now);
//output it to compare
echo '1 week ago: ' . date('r', weekAgo));