为什么可以';t我更改日期的时间不到29分钟,为什么PHP的time()和date()组合返回的时间是';还


Why can't I change the time for a date for less than ~29 minutes and why is the PHP time() and date() combo return a time that's ~27 minutes off?

所以我有一块PHP代码,我只想有一个当前日期的UNIX时间戳,一个早于25分钟的时间戳。UNIX时间戳会相应地发生变化,但当我使用每个时间戳并将其转换为带有日期('Md,Y a--h:M:s',$current)或日期('md,Y a-h:M:s'、$old)的格式化日期时,两个时间都完全相同。这似乎是一个大于29分钟的变化,但我不确定为什么。问题的第二部分:使用time()和date(),甚至将时区设置为我自己的时区,它返回的时间大约落后20-30分钟,这也让我担心

<?
date_default_timezone_set('MST');
$current = time();
$old = time() - (25 * 60);
echo $current . ' - ' . $old; // Prints 1330473445 - 1330471945
echo date('h:m:s A -- M d, Y',$current); // 04:02:25 PM -- Feb 28, 2012
echo date('h:m:s A -- M d, Y', $old); // 04:02:25 PM -- Feb 28, 2012
?>

这就是它在我的屏幕上打印的方式。不同的UNIX时间戳,但格式相同的日期。我想你指的是系统时钟,就像我需要通过BIOS编辑的时钟一样。就我电脑上的时钟而言,这就是我所比较的。

更新

已解决。使用"m"表示秒,而不是使用"i"

原因是您使用了"h:m:s"

echo date("M d, Y A -- h:i:s",$ut); and your problem is solved

m不是"分钟"m=月
i=分钟

我知道这是邪恶的,我只是自己爱上了它一段时间;)
以下是文档:http://www.php.net/manual/de/function.date.php

这会给您带来什么:

<?php
echo $current.' - '.$old;
?>

您也可以使用strtotime("-25分钟")作为第二个参数。

另外,我认为你指的是i,而不是m。这是使用月份而不是分钟。尝试使用i,看看它是否有效?