PHP gets today, yesterday, tomorrow's date

Source: Internet
Author: User

[PHP]View Plaincopyprint?
  1. <?php
  2. Echo "Today:". Date ("y-m-d")."       <br> ";
  3. Echo "Yesterday:".        Date ("y-m-d",strtotime ("-1 day"), "<br>";
  4. Echo "Tomorrow:".  Date ("y-m-d",strtotime ("+1 Day")).    "<br>";
  5. Echo "One week later:".  Date ("y-m-d",strtotime ("+1 Week")).       "<br>";
  6. echo "2 days a week, four hours, two seconds later:".  Date ("y-m-d g:h:s",strtotime ("+1 Week 2 days 4 hours 2 seconds").       "<br>";
  7. Echo "Next week Four:".  Date ("y-m-d",strtotime ("next Thursday")).       "<br>";
  8. Echo "last Monday:". Date ("y-m-d",strtotime ("last Monday"))."       <br> ";
  9. echo "One months ago:". Date ("y-m-d",strtotime ("last month"))."       <br> ";
  10. echo "One months later:". Date ("y-m-d",strtotime ("+1 Month"))."       <br> ";
  11. Echo "Ten years later:". Date ("y-m-d",strtotime ("+10 Year"))."      <br> ";
  12. ?>

The function of the Strtotime () function is to parse a datetime description into a Unix timestamp

int strtotime (string time [, int now])

PHP Week Get Code:

    1. Date ("L");
    2. Data can be obtained in English for weeks such as Sunday
    3. Date ("W");
    4. This can get the numbers for weeks like 123, note that 0 is Sunday

Get Chinese week can be like this

    1. $weekarray =array ("Day", "one", "two", "three", "four", "five", "six");
    2. echo "Week". $weekarray [Date ("W")];

Gets the specified date:

    1. $weekarray =array ("Day", "one", "two", "three", "four", "five", "six");
    2. echo "Week". $weekarray [Date ("W", "2011-11-11")];

Because the date function is so powerful, he can do all this work. I'm attaching a table in the handbook.

    1. A-"AM" or "PM"
    2. A-"AM" or "PM"
    3. D-A few days, two digits, if less than two is the front 0; such as: "01" to "31"
    4. D-Days of the week, three English letters; such as: "Fri"
    5. F-month, full name in English; such as: "January"
    6. H-12 hours of the hour; such as: "01" to "12"
    7. H-hour of 24-hour system; such as: "00" to "23"
    8. G-12 hours of the hour, less than two digits do not fill 0; such as: "1" to 12 "
    9. G-24 hours of the hour, less than two does not fill 0; such as: "0" to "23"
    10. I-minute; such as: "00" to "59"
    11. J-A few days, two digits, if less than two bits do not fill 0; such as: "1" to "31"
    12. L-Day of the week, English full name; such as: "Friday"
    13. M-month, two digits, if less than two digits in front of 0; such as: "01" to "12"
    14. N-month, two digits, if less than two digits does not fill 0; such as: "1" to "12"
    15. M-month, three letters of English; such as: "Jan"
    16. S-second; such as: "00" to "59"
    17. S-End With English ordinal number, two English letters; such as: "th", "nd"
    18. T-the number of days in the specified month; such as: "28" to "31"
    19. U-Total number of seconds
    20. W-Number of days of the week, such as: "0" (Sunday) to "6" (Saturday)
    21. Y-year, four digits; such as: "1999"
    22. Y-year, two digits; such as: "99"
    23. Z-the day ordinal of a year; such as: "0" to "365"

The above detailed introduction of the PHP week to get the method and the date function of the introduction, everyone try it

PHP gets today, yesterday, tomorrow's date

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.