Today, October 31, execute the code:
echo date('Ym', strtotime("-1 month"));
The returned result is 201410, is not the description similar to untrusted strtotime("-1 month")
?
Defines the time zone.
Php-v
PHP 5.4.33-1~dotdeb.0 (CLI) (built:sep 19 2014 12:00:21)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
Reply content:
Today, October 31, execute the code:
echo date('Ym', strtotime("-1 month"));
The returned result is 201410, is not the description similar to untrusted strtotime("-1 month")
?
Defines the time zone.
Php-v
PHP 5.4.33-1~dotdeb.0 (CLI) (built:sep 19 2014 12:00:21)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;月份直接减1 ,当前日期 10月 31号 减一变成 9月31号 即是 10月1号
This is a PHP bug, you can specify the start time of the month.
$base = strtotime (Date (' Y-m ', Time ()). '-01 00:00:01 ');
echo Date (' m/y ', Strtotime ('-1 month ', $base));
Do you not define a time zone true real man? After defining the time zone my side is normal, PHP5.5 environment.
date_default_timezone_set("Asia/Shanghai");echo date("Y-m", strtotime("-1 month"));
May really like @ beautiful style is said to be a bug (read the manual does not know is not 5.2.7 of the bug), according to his definition of the relative time after the normal.
echo date("Y-m", strtotime("-1 month", strtotime("first day of this month")));