昨天工作正常,没有更改代码.
echo date("M", strtotime("-3 month", time()) );
echo date("M", strtotime("-2 month", time()) );
echo date("M", strtotime("-1 month", time()) );
echo date("M", time());
Run Code Online (Sandbox Code Playgroud)
它昨天产生的产量正如你所料 - 即4月,5月,6月,7月
今天它与五月五月七月相呼应
有任何想法吗?
提前致谢.
我看到php有月加法和减法有奇怪的问题.
我的问题是:
几个例子:
echo date('Y-m-d',strtotime('2011-03-31 -1 months')); //2011-03-03
echo date('Y-m-d',strtotime('2011-03-30 -1 months')); //2011-03-02
echo date('Y-m-d',strtotime('2011-03-29 -1 months')); //2011-03-01
echo date('Y-m-d',strtotime('2011-03-28 -1 months')); //2011-02-28
Run Code Online (Sandbox Code Playgroud)
我有一个脚本,可以在PHP中获取当前和上个月:
$currentMonth = date('m');
//Expected:07
//Result:07
$lastMonth = date('m', strtotime('-1 months'));
//Expected:06
//Result:07
Run Code Online (Sandbox Code Playgroud)
今天恰好是7月31日或月底.这个结果是从PHP预期的吗?
使用-31天时,结果如预期:
$lastMonth = date('m', strtotime('-31 days'));
//Expected:06
//Result:06
Run Code Online (Sandbox Code Playgroud) 这只发生在31日到目前为止
echo date('F',strtotime('this month')); //May
echo date('F',strtotime('next month'));//July
echo date('F',strtotime('+1 month'));//July
Run Code Online (Sandbox Code Playgroud)
据我所知,六月是五月之后.但是我猜想从现在开始增加31天后,php就变得懒惰了,整整一个月都没有了.
无论长度如何,我怎样才能安全地获得下个月?理想情况下使用strttotime
编辑忘了提,为什么我希望使用strtotime是我使用搜索框来查找解释用户输入strtotime的事件