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


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

我发现这两个返回的数字不同,但都应该给出一个时间戳。

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