PHP Strtotime for explanation

Source: Internet
Author: User
$t = ' 2011-01-31 17:21:22 ';
Print_r (Array (
Date (' Y year m month ', Strtotime ($t)),
Date (' Y year m month ', Strtotime (' + 1 month ', Strtotime ($t))),
Date (' Y year m month ', Strtotime (' + 2 month ', Strtotime ($t))),
));
Exit
Why is it all March?


Reply to discussion (solution)

$t time is January 31 February not so the second element of the array is also March.

February No 31st
So January 31 plus one months will be March.

$t = ' 2011-01-28 17:21:22 '; Change to 28th Print_r (Array (            ' Y year M month ', Strtotime ($t)),            date (' Y year m month ', Strtotime (' + 1 month ', Strtotime ($t))),            date (' Y year m month ', Strtotime (' + 2 month ', Strtotime ($t))));
Array (    [0] = January 2011    [1] = February 2011    [2] = March 2011)


Strtotime is a feature with auto-correct date
Print_r (Array (            the date (' Y year m D Day ', Strtotime (' 2011-02-31 ')),            date (' Y year m D Day ', Strtotime (' 2011-04-31 ')),            Date (' Y year m D Day ', Strtotime (' 2011-06-31 ')));
Array (    [0] = March 03, 2011    [1] = May 01, 2011    [2] = July 01, 2011)
  • 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.