从现在开始使用PHP 5.2获得下一个10个月


Getting the next 10th of a month from now using PHP 5.2?

我已经问过类似的问题了:

从现在开始得到下一个月的10个月?

解决方案是:

date('d.m.Y', strtotime('+10 days', strtotime('first day of ' . ((int)date('j') < 10 ? 'this' : 'next' ) . ' month')));

但是我接受的解决方案只适用于PHP 5.3+(因为"第一天")。我需要PHP 5.2的解决方案。如何在PHP 5.2中解决这个问题?

谢谢!

注意:我不能更新PHP版本:)。

你可以试试-

echo date('d-m-Y', strtotime(' + 1 month', strtotime(date('Y-m-10'))));

if(strtotime(date('Y-m-10 00:00:00')) < time())
    echo date('d-m-Y', strtotime(' + 1 month', strtotime(date('Y-m-10'))));
else
    echo date('10-m-Y');

您可以尝试使用mktime()

// Check if you need next or current month
$month = date('d') < 10 ? date('m') : date('m') + 1;
// mktime will fix 13th month issue converting it to next ears first month
$timestamp = mktime(0, 0, 0, $month, 10, date('Y'));
$date = date('Y-m-d', $timestamp);

Try mktime()

$month = (int)date('j') <10 ?Date ('n'): Date ('n')+1;

("d.m.

回声日期。Y ', mktime(0, 0, 0,美元月,日期("j")+ 15,日期(Y)))