"-1 month" for Time Calculation in PHP "?

Source: Internet
Author: User
Today, July 15, October 31, run the code: {code ...} the returned result is 201410. Does it mean strtotime (& quot;-1 month & quot;) is untrusted? Defines the time zone. Php-vPHP5.4.33-1 ~ Dotdeb.0 (cli) (built: Sep19201412: 00: 21) Copy... today, that is, July 22, October 31, run the following code:

echo date('Ym', strtotime("-1 month"));

The returned result is 201410. Is it similar?strtotime("-1 month")Is it untrusted?

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, July 22, October 31, run the following code:

echo date('Ym', strtotime("-1 month"));

The returned result is 201410. Is it similar?strtotime("-1 month")Is it untrusted?

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; the month is directly reduced by 1. The current date December 1, is changed to January 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 ));

Is it true that the time zone is not defined? After the time zone is defined, it is normal for me to use the PHP5.5 environment.

date_default_timezone_set("Asia/Shanghai");echo date("Y-m", strtotime("-1 month"));

It may be true that @ beautiful style is a BUG (I don't know if it is the BUG in 5.2.7 after reading the manual). It is normal after defining the relative time according to his statement.

echo date("Y-m", strtotime("-1 month", strtotime("first day of this month")));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.