PHP将月份和天数添加到当前时间()和卵形周末

PHP将月份和天数添加到当前时间()和卵形周末,php,unix-timestamp,strtotime,Php,Unix Timestamp,Strtotime,我需要在PHP中向当前时间()添加N个月和M天。我目前的解决方案很简单,但我想知道它是否更简单:) 我还想知道是否有机会在目标日期避免周末(周六和周日)?是的,您可以简化为: $my_time = strtotime("+6 days 1 month", time()); 或: 请参见是的,您可以将其简化为: $my_time = strtotime("+6 days 1 month", time()); 或: 请参见我会使用该类,因为它比strotime快得多 $date = new Da

我需要在PHP中向当前时间()添加N个月和M天。我目前的解决方案很简单,但我想知道它是否更简单:)


我还想知道是否有机会在目标日期避免周末(周六和周日)?

是的,您可以简化为:

$my_time = strtotime("+6 days 1 month", time());
或:


请参见

是的,您可以将其简化为:

$my_time = strtotime("+6 days 1 month", time());
或:

请参见

我会使用该类,因为它比strotime快得多

$date = new DateTime();
$date->add(new DateInterval('P1M6D'));
echo $date->format('Y-m-d');
可以找到DateInterval的详细synthax信息。

我会使用该类,因为它比StrotTime快得多

$date = new DateTime();
$date->add(new DateInterval('P1M6D'));
echo $date->format('Y-m-d');
可以找到DateInterval的详细synthax信息。

尝试以下方法 使用strotime()函数添加天月年

对于日添加 日期(“Y-m-d”,标准时间(“3天”); 月份添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
年度添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
对于日-月-年添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
用于减去年月日

date('Y-m-d', strtotime("-1 days 1 month 1 year "));
只需使用(+-)符号

尝试以下方法 使用strotime()函数添加天月年

对于日添加 日期(“Y-m-d”,标准时间(“3天”); 月份添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
年度添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
对于日-月-年添加

date('Y-m-d', strtotime("+3 month"));
date('Y-m-d', strtotime("+3 year"));
date('Y-m-d', strtotime("+1 days 1 month 1 year "));
用于减去年月日

date('Y-m-d', strtotime("-1 days 1 month 1 year "));

只需使用(+-)符号

strottime(“+6天1个月”,time());应执行其TRTOTIME(“+6天1个月”,time());应该做的我怎么会错过这个。我希望这样的事情能奏效,而且确实如此。谢谢。啊,我怎么会错过这个。我希望这样的事情能奏效,而且确实如此。谢谢。