PHP uses date and strtotime functions to output a specified date method _php tips

Source: Internet
Author: User

This example describes how PHP uses the date and Strtotime functions to output the specified dates. Share to everyone for your reference. The specific methods are analyzed as follows:

The date and Strtotime functions in PHP are all for dates, but it's not the same in the generation that date and strtotime, one is the number date and the other is the Unix timestamp, but we all can generate the same date, and here's a look at two examples of functions.

PHP is often used in the date function and Strtotime function, these 2 functions are not unfamiliar to everyone, today and you share the use of skills.

strtotime-resolves a date-time description of any English text to a Unix timestamp

Copy Code code as follows:
Date_default_timezone_set (' Asia/shanghai ');
Calculate the time of yesterday, we use:
Date ("Ymd", Time ()-3600);
Generate yesterday's time
Date ("Ymd", Strtotime (' Yesterday '));
Date ("Ymd", Strtotime ('-1 day '));
Generate time before the day before
Date ("Ymd", Strtotime (' Yesterday-1 Day '));
Date ("Ymd", Strtotime ('-2 day '));
Build time after 3 days
Date ("Ymd", Strtotime (' +3 Day '));
Generated one months ago
Date ("Ymd", Strtotime ('-1 month '));
Generate the last day of the next month
Date ("Ymd", Strtotime (' Last day of next month ');
Monday, next week.
Date ("Ymd", Strtotime (' next Monday '));

I hope this article will help you with your PHP program design.

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.