我可以在上个月的上个星期一找到,但我还需要两个月前的上个星期一吗?
strtotime("last Monday of June 2015") //gives previous month's last Monday
我应该怎样做才能找到上个星期一的-2个月?
我将以编程方式使用
答案 0 :(得分:3)
试试这个:
// Past
strtotime("last Monday of -2 months");
// Future
strtotime("last Monday of +2 months");
像魅力一样! PHP的strtotime
非常聪明。
答案 1 :(得分:2)
在我看来很脏,但是这很有用
$no_months = -2; // Number of months from now
echo date('d/M/Y' , strtotime('Last monday of ' . date('M Y', strtotime($no_months . ' months'))));
基本上这只是动态创建原始字符串的“2015年6月”,“2015年5月”部分,具体取决于您在var中设置的月份的负值/正值。