为什么今天'在日期结束时返回额外的分钟数


why does 'today' return extra minutes on the end of a date

我需要在php中获得给定日期的第一和最后一秒。当我使用这个:

$date2 = strToTime('today');
echo Date('Y-m-d h:m:s', $date2) . "</br>";

得到2013-03-24 12:03:00。但是为什么要多花3分钟呢?应该是12:00:00。我需要一个解决方案,可以每次工作,即使在奇怪的闰年的情况下,因为这段代码将启动支付。

http://ideone.com/H2JQ0D

PHPm是月而不是分钟

代替

echo Date('Y-m-d h:m:s', $date2)
                   ^--------------------- Months

echo Date('Y-m-d h:i:s', $date2)
                   ^--------------------- Correct Value

为什么不这样做呢:

$firstSecond = date('Y-m-d') . ' 00:00:00'; // first second of today
$lastSecond  = date('Y-m-d') . ' 23:59:59'; // last second of today

等待未来的某一天

$time = strtotime('yesterday');
$firstSecond = date('Y-m-d', $time) . ' 00:00:00'; // first second of yesterday
$lastSecond  = date('Y-m-d', $time) . ' 23:59:59'; // last second of yesterday

编辑::现在我想起来了。如果整个目的是查看记录是否在当天出现,你可以很容易地这样做:

$recordTime = strtotime('2013-03-24 14:12:23');
if ($recordTime >= strtotime('today') && $recordTime < strtotime('tomorrow') {
    // ... do stuff
}