php uses the date and strtotime functions to output the method of specifying the date

  • 2021-08-03 09:20:48
  • OfStack

This article illustrates how php uses date and strtotime functions to output a specified date. Share it for your reference. Specific methods are analyzed as follows:

In php, date and strtotime functions are all operated on dates, but date and strtotime are different from each other in generating, one is a digital date and one is an Unix timestamp, but we can all generate the same date. Let's look at the examples of two functions below.

date function and strtotime function are often used in php. These two functions are no strangers to everyone. Today, I will share my skills with you.

strtotime-Parses the date-time description of any English text into an Unix timestamp

date_default_timezone_set('Asia/Shanghai');
// To calculate yesterday's time, we use:
date("Ymd",time()-3600);
// Generate yesterday's time
date("Ymd",strtotime('yesterday'));
date("Ymd",strtotime('-1 day'));
// Generate the time of the day before yesterday
date("Ymd",strtotime('yesterday -1 day'));
date("Ymd",strtotime('-2 day'));
// Generate 3 The time after days
date("Ymd",strtotime('+3 day'));
// Generate 1 Three months ago
date("Ymd",strtotime('-1 month'));
// Generate the last of next month 1 The time of days
date("Ymd",strtotime('last day of next month'));
// The week of next week 1
date("Ymd",strtotime('next monday'));

I hope this article is helpful to everyone's PHP programming.


Related articles: