PHP strotime+1个月,返回23:59

PHP strotime+1个月,返回23:59,php,Php,我可以使用strotime有+1个月的时间,但我如何返回那天23:59:59 例如,现在是2013-06-19 03:28如果我加1个月,那么它将返回2013-07-19 03:28,但我需要2013-07-19 23:59。虽然orangepill的答案很有用,但我认为这更清楚: <?php // You time as Unix timestamp $now = strtotime('2013-06-19 03:28'); $d = new DateTime(); // When

我可以使用strotime有+1个月的时间,但我如何返回那天23:59:59

例如,现在是2013-06-19 03:28如果我加1个月,那么它将返回2013-07-19 03:28,但我需要2013-07-19 23:59。

虽然orangepill的答案很有用,但我认为这更清楚:

<?php

// You time as Unix timestamp
$now = strtotime('2013-06-19 03:28');

$d = new DateTime();

// Whenever doing date calculations, timezone is important. Set it to "UTC" if you don't care.
$d->setTimeZone(new DateTimeZone('America/Detroit'));

// Initialize date ( - but remember, DateTime can take many other forms of date input)
$d->setTimeStamp($now);

// Increase date by 1 month.
$d->add(new DateInterval('P1M'));

// Overwrite the "clock" part of the date
$d->setTime(23, 59, 59);

// Display the result:
var_dump($d);
尽管orangepill的答案很有用,但我认为这一点更清楚:

<?php

// You time as Unix timestamp
$now = strtotime('2013-06-19 03:28');

$d = new DateTime();

// Whenever doing date calculations, timezone is important. Set it to "UTC" if you don't care.
$d->setTimeZone(new DateTimeZone('America/Detroit'));

// Initialize date ( - but remember, DateTime can take many other forms of date input)
$d->setTimeStamp($now);

// Increase date by 1 month.
$d->add(new DateInterval('P1M'));

// Overwrite the "clock" part of the date
$d->setTime(23, 59, 59);

// Display the result:
var_dump($d);

显示代码。这可能会有帮助。有没有人像我一样研究技术来寻找一天、一周、一个月或一年的结束?我刚刚意识到,与直觉相反,至少出于编程目的,第二天的开始可能是我真正需要的。23:59是一天的结束吗?不,还有整整一分钟。23:59:59怎么样?显然,还有一秒钟。好的,那么23:59:59.999?也许这已经足够好了,但这并不像寻找第二天的午夜那样直接,因为前一天的午夜才真正结束。e、 strotime“下个月的第一天午夜”:显示代码。这可能会有帮助。有没有人像我一样研究技术来寻找一天、一周、一个月或一年的结束?我刚刚意识到,与直觉相反,至少出于编程目的,第二天的开始可能是我真正需要的。23:59是一天的结束吗?不,还有整整一分钟。23:59:59怎么样?显然,还有一秒钟。好的,那么23:59:59.999?也许这已经足够好了,但这并不像寻找第二天的午夜那样直接,因为前一天的午夜才真正结束。e、 g.STROTIME‘下个月的第一天午夜’: