PHP有DateTime
类可用它应使用的date
和strtotime
功能,因为你可能意味着使用什么时区因此,当涉及到DST和其他许多事情时,您可以是“安全的”。
如何使用它来解决你的问题:
$date = '2011-11-30'; // our date that we deal with
$tz = new DateTimeZone('Europe/London');
// create new DateTime object specifying the format and the date we create from as well as the time zone we're in
$dt = DateTime::createFromFormat('Y-m-d', $date, $tz);
// let's substract 1 month from current DateTime object
$sub = $dt->sub(new DateInterval('P1M')); // P stands for PERIOD, 1 stands for ONE and M stands for MONTH - so it means we're substracting period of 1 month
// output the new date
echo $sub->format('Y-m-d);
这是正确的做法。即使他们已经工作,其他人也只是在努力工作。 – aartist
@aartist:请告诉我为什么我的解决方案不是“正确的做法”。 – Bluewind
@蓝风让2011-10-24。您的解决方案错了。 – Peter