PHP strtotime:上个月

Mar*_*tin 18 php date strtotime

可能重复:
如何使用strtotime和日期获得相对于今天的上个月和年份?

今天是12月31日但是strtotime("-1 months")12月返回:

echo date("Y-m", strtotime("-1 months"));
Run Code Online (Sandbox Code Playgroud)

同样的 strtotime("last month")

我怎样才能正确返回上个月(11月)?

测试:http://codepad.viper-7.com/XvMaMB

sal*_*the 31

strtotime("first day of last month")
Run Code Online (Sandbox Code Playgroud)

first day of相对格式手册页中详述的重要部分.


示例:http://codepad.viper-7.com/dB35q8(今天的硬编码日期)

  • "下个月的第一天"在PHP 5.2.4中不起作用 (2认同)

Ola*_*che 10

strtotime("-1 months")2012-11-31,但是没有11月31日.这是过去的一天2012-11-30,这给了2012-12-01.当你这样做时,你会看到它

echo date("Y-m-d", strtotime("-1 months"));
Run Code Online (Sandbox Code Playgroud)

给出输出

2012年12月1日

请参阅键盘