PHP - 为什么 time() return 的秒数与 strtotime(date()) 不同

PHP - Why does time() return different number of seconds than strtotime(date())

我发现这两个 returns 不同的数字 - 但都应该给出时间戳。

strtotime( date("Y-m-d h:i:s") ); //currently 1447570497
time(); //currently 1447613697

差异恰好是 12 小时(43200 秒),同样的事情发生在:

(new DateTime( date("Y-m-d h:i:s") ))->getTimestamp(); //acts like strtotime+date
(new DateTime("now"))->getTimestamp(); //acts like time()

为什么会这样? (因为是 12 小时,所以可能不是夏令时问题)

它有 24 小时和 12 小时模式吗?

您需要在 date() 中使用 H 以获得中午 12 点后的正确时间。否则你将休息 1 - 12 小时。

strtotime( date("Y-m-d H:i:s") ); //currently 1447570497