Home  >  Article  >  Backend Development  >  PHP uses date and strtotime functions to output a specified date, datestrtotime_PHP tutorial

PHP uses date and strtotime functions to output a specified date, datestrtotime_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:06843browse

php uses the date and strtotime functions to output the specified date, datestrtotime

The example in this article describes how PHP uses the date and strtotime functions to output a specified date. Share it with everyone for your reference. The specific method analysis is as follows:

In php, the date and strtotime functions both operate on dates, but date and strtotime are different when generating them. One is a digital date and the other is a Unix timestamp, but we can both generate the same date, as follows Let’s look at two examples of functions.

The date function and strtotime function are often used in PHP. These two functions must be familiar to everyone. Today I will share with you the usage tips.

strtotime — Parse any English text datetime description into a Unix timestamp

Copy code The code is as follows:
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 time after 3 days
date("Ymd",strtotime('+3 day'));
//Generate time one month ago
date("Ymd",strtotime('-1 month'));
//Generate the time of the last day of the next month
date("Ymd",strtotime('last day of next month'));
//Monday of next week
date("Ymd",strtotime('next monday'));

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/911908.htmlTechArticleHow to use date and strtotime functions to output a specified date in php, datestrtotime This article describes how to use date and strtotime functions in php to output How to specify a date. Share it with everyone for your reference...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn