How to use the Date () Date function in PHP _ PHP Tutorial

Source: Internet
Author: User
Summary of how to use the Date () Date function in PHP. The format parameter description is required for the syntax date (format, timestamp. The format of the specified timestamp. Optional. The specified timestamp. The default value is the current date and time. Syntax
Date (format, timestamp) parameter description
Format is required. The format of the specified timestamp.
Optional. The specified timestamp. The default value is the current date and time.

Find that the previous day is time ()-60*60*24;
Find that the time of the previous year is time () * 60*60*24*365.
So how can we replace this number with the date format? we need to use the date () function.
$ T = time (); www.3ppt.com
Echo date ("y-m-d h: I: s", $ t );
The format of each parameter is as follows:
A-"am" or "pm"
A-"am" or "pm"
D-a few days, two digits. if there are less than two digits, fill in the first zero. for example, "01" to "31"
D-the day of the week, with three English letters, for example, "fri"
F-month, full English name; for example: "January"
H-12 hours, for example, "01" to "12"
H-24 hours, for example, "00" to "23"
Hours in the g-12 hour format. less than two hours do not fill in zero. for example: "1" to 12"
Hours in the g-24-hour format. less than two hours do not fill in zero. for example: "0" to "23"
I-minutes; for example: "00" to "59"
J-a few days, two digits. if less than two digits are left blank, for example, "1" to "31"
L-the day of the week, full name in English; for example: "Friday"
M-month, two digits. if there are less than two digits, add zero in front, for example, "01" to "12"
N-month, two digits. if less than two digits are left blank, for example, "1" to "12"
M-month, with three English letters, for example, "jan"
S-seconds; for example: "00" to "59"
The end of the s-character is followed by an English sequence, with two English letters, for example, "th", "nd"
T-specifies the number of days in a month, for example, "28" to "31"
U-total seconds
W-number of weeks, for example, "0" (Sunday) to "6" (Saturday)
Y-year, four digits, such as: "1999"
Y-year, two digits, for example, "99"
Z-the day of the year, for example, "0" to "365"
Other characters not in the upper column are listed directly.

Php date-format date
The first parameter of the date () function specifies how to format the date/time. It uses letters to indicate the date and time formats. Some available letters are listed here:
Day in d-month (01-31)
M-current month, in numbers (01-12)
Y-current year (four digits)
You can find all the letters that can be used in the format parameters in our php date reference manual.
You can insert other characters between letters, such as "/", ".", or "-" to add additional formats:

The code is as follows:


Echo date ("y/m/d ");
Echo"
";
Echo date ("y. m. d ");
Echo"
";
Echo date ("y-m-d ");
?>

The format parameter description is required. The format of the specified timestamp. Optional. The specified timestamp. The default value is the current date and time. you need to find the time of the previous day...

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.