PHP calculates the time after (before) the current time
There is a very powerful function in PHP, the strtotime() function. This function has an extremely powerful way to use it. It is mentioned in the manual, but it is estimated that in actual applications Not many people can think of it.
In order to calculate the date N days after the current time, I accidentally discovered this function after writing a very complicated function. I record it now to avoid forgetting it in the future
The timestamp one week after the current time: strtotime(”+1 week”), that’s it. It will be like this after one week. I think everyone will know it after N weeks, hehe...
Then draw inferences, what about one month later? It should be strtotime("+1 months");
What about the time after 5 days? Of course it is: strtotime("+5 days");
What about 12 hours later? strtotime("+12 hours");
Of course after 20 minutes it will be: strtotime("+20 minutes");
After 30 seconds it will be strtotime("+30 seconds");
What about the time last Saturday? It should be strtotime("Last Saturday");
Of course next Saturday is strtotime("Next Saturday");
Of course you can also write it as complicated as the current time is one month, two weeks, zero three days, zero The time after 4 hours, 16 minutes and 32 seconds:
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 "+", and the time before it is of course "-"!
The above introduces how PHP calculates the time after (before) the current time, including aspects. I hope it will be helpful to friends who are interested in PHP tutorials.