我可以使用strtotime +1个月但是如何返回那天23:59:59?
例如现在 2013-06-19 03:28 如果我加1个月那么它将返回 2013-07-19 03:28 但我需要 2013-07-19 23:59 。
答案 0 :(得分:4)
date("Y-m-d 23:59:59", strtotime("+1 month"));
答案 1 :(得分:3)
虽然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);