Php uses the date and strtotime functions to output the method of specifying a date

Source: Internet
Author: User
This article describes how to use the date and strtotime functions of php to output the specified date. The example summarizes the methods used to generate various date formats, which is very useful. For more information, see

This article describes how to use the date and strtotime functions of php to output the specified date. The example summarizes the methods used to generate various date formats, which is very useful. For more information, see

This example describes how php outputs a specified date using the date and strtotime functions. Share it with you for your reference. The specific method is analyzed as follows:

In php, the date and strtotime functions operate on the date, but the date and strtotime functions are different in the generation process. One is the numeric date and the other is the Unix timestamp, but we can all generate the same date. Let's look at two examples of functions below.

The date and strtotime functions are often used in php. These two functions are certainly not unfamiliar to everyone. I would like to share with you the tips for using them today.

Strtotime-parses the date and time descriptions of any English text into Unix timestamps

The Code is as follows:

Date_default_timezone_set ('Asia/Shanghai ');
// Calculate the time of yesterday. We use:
Date ("Ymd", time () to 3600 );
// Generate the time of yesterday
Date ("Ymd", strtotime ('yesterday '));
Date ("Ymd", strtotime ('-1 Day '));
// Generate the day before yesterday
Date ("Ymd", strtotime ('Yesterday-1 Day '));
Date ("Ymd", strtotime ('-2 Day '));
// Generate three days later
Date ("Ymd", strtotime ('+ 3 Day '));
// Generate a month ago
Date ("Ymd", strtotime ('-1 month '));
// Generate the last day of the next month
Date ("Ymd", strtotime ('Last day of next month '));
// Monday of the next week
Date ("Ymd", strtotime ('Next Monday '));

I hope this article will help you with PHP programming.

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.