The use of date () Time function in PHP summary _php tips

Source: Internet
Author: User
Grammar
Date (format,timestamp) parameter description
Format required. Specify the format of the timestamp.
Timestamp optional. Specify the time stamp. The default is the current date and time

To find out the day before is time () -60*60*24;
To find out the time of the previous year is timing () *60*60*24*365
So how do I change this number to date format, and 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 expressed separately:
A-"AM" or "PM"
A-"AM" or "PM"
D-A few days, two digits, if less than two digits before the 0; such as: "01" to "31"
D-Days of the week, three English letters; such as: "Fri"
F-month, full name in English; such as: "January"
Hours of h-12 hours; such as: "01" to "12"
Hours of h-24 hours; such as: "00" to "23"
G-12 hours, less than two-bit not to fill 0; such as: "1" to 12 "
G-24 hours, less than two-bit not to fill 0; such as: "0" to "23"
I-minute; such as: "00" to "59"
J-A few days, two digits, if less than two digits do not fill 0; such as: "1" to "31"
L-Days of the week, full name in English; such as: "Friday"
M-month, two digits, if less than two digits in front of the 0; such as: "01" to "12"
N-month, two digits, if less than two digits will not fill 0; such as: "1" to "12"
M-month, three English letters; such as: "The"
S-seconds; such as: "00" to "59"
S-word tail plus English ordinal number, two English letters; such as: "th", "nd"
T-Specifies the number of days of the month; such as: "28" to "31"
U-Total number of seconds
W-Number of days of the week, such as: "0" (Sunday) to "6" (Saturday)
Y-year, four digits; such as: "1999"
Y-year, two digits; such as: "99"
Z-the day ordinal of the year; such as: "0" to "365"
Other characters that are not listed directly list the character

PHP Date-format Date
The first parameter of the date () function prescribes how the date/time is formatted. It uses letters to indicate the format of dates and times. Here are some of the letters available:
D-Days of the month (01-31)
M-Current month, in Digital (01-12)
Y-the current year (four digits)
You can find all the letters that you can use in the format parameters in our PHP date reference manual.
You can insert other characters between letters, such as "/", "." or "-", so you can add additional formatting:
Copy Code code as follows:

<?php
echo Date ("y/m/d");
echo "<br/>";
echo Date ("Y.M.D");
echo "<br/>";
echo Date ("y-m-d");
?>

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.