PHP calculates the time after (before) the current time

Source: Internet
Author: User
: This article describes how to calculate the time after (before) the current time in PHP. if you are interested in the PHP Tutorial, refer to it. PHP calculates the time after (before) the current time


There is a very powerful function in PHP, strtotime () function. this function has a very bad usage method, which is described in the manual, however, it is estimated that there are not many people to think of in practical applications.

I accidentally discovered this function after I wrote a very complex function to calculate the date of the current N days. now I recorded it so that I could not forget it later.

The timestamp after the current time is one week: strtotime ("+ 1 week"). That's all. after one week, I think you should know it after N weeks, hey ......

Then, what about a month later? It should be strtotime ("+ 1 months ");

Five days later, of course, is: strtotime ("+ 5 days ");

What about 12 hours later? Strtotime ("+ 12 hours ");

20 minutes later, of course: strtotime ("+ 20 minutes ");

30 seconds later is strtotime ("+ 30 seconds ");

What about last Saturday? It should be strtotime ("Last Saturday");

Next Saturday is of course strtotime ("Next Saturday ");

Of course, you can also write it as follows: the current time is one month, two weeks, three days, four hours, 16 minutes, and 32 seconds later:

Date ("Y-m-d H: I: s", strtotime ("+ 1 months + 1 week + 3 days + 4 hours + 16 minutes + 32 seconds "));

The time after the current time is "+". of course, you can use "-" for the previous time!

The above section describes the time (before) after the current PHP computing time, including the relevant content, and hopes to help those who are interested in the PHP Tutorial.

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.