PHP date () function in detail (_php) tutorial

Source: Internet
Author: User
Tags echo date local time
Let's look at some of the usage and basic details of the date () function in PHP, as you can see here.

Date function usage

The code is as follows Copy Code

Date ($t);

The format is as follows:

Format displayed: Year-month-day hours: minutes: seconds
Relevant time parameters:
A-"AM" or "PM"
A-"AM" or "PM"
D-A few days, two digits, if less than two is the front 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"
H-12 hours of the hour; such as: "01" to "12"
H-hour of 24-hour system; such as: "00" to "23"
G-12 hours of the hour, less than two digits do not fill 0; such as: "1" to 12 "
G-24 hours of the hour, less than two does not fill 0; such as: "0" to "23"
I-minute; such as: "00" to "59"
J-A few days, two digits, if less than two bits do not fill 0; such as: "1" to "31"
L-Day of the week, English full name; such as: "Friday"
M-month, two digits, if less than two digits in front of 0; such as: "01" to "12"
N-month, two digits, if less than two digits does not fill 0; such as: "1" to "12"
M-month, three letters of English; such as: "Jan"
S-second; such as: "00" to "59"
S-End With English ordinal number, two English letters; such as: "th", "nd"
T-the number of days in the specified 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 a year; such as: "0" to "365"
You can freely set the contents of the display, the connection symbol or display location, such as Date ("m-d H") or date ("DmY"); Date processing in PHP >, etc.


Instance

1, year-month-day

The code is as follows Copy Code

echo Date (' y-m-j ');

2007-02-6


echo Date (' y-n-j ');

07-2-6

Uppercase Y represents the year four digits, while lowercase y represents the two digits of the year;
Lowercase m represents the number of months (with leading), while lowercase n indicates no leading month number.

The code is as follows Copy Code

echo Date (' y-m-j ');

2007-feb-6

echo Date (' y-m-d ');

2007-02-06

The uppercase M represents the 3 abbreviated characters of the month, while the lowercase m represents the number of the month (with leading 0);
J with no uppercase, only lowercase J indicates the date of the month, no leading o, or lowercase D if a month with a leading is required.

The code is as follows Copy Code

echo Date (' y-m-j ');

2007-feb-6

echo Date (' Y-f-js ');

2007-february-6th

Uppercase M represents the 3 abbreviated characters of the month, while uppercase F indicates the full written English of the month. (No lowercase f)
Uppercase S represents the suffix of the date, such as "St", "nd", "rd", and "th", depending on the date number.

Summary:
Indicates that the year can be in uppercase Y and lowercase y;
Indicates that the month can be in uppercase F, uppercase M, lowercase m, and lowercase n (two ways of representing characters and numbers, respectively);
Indicates that the day can be in lowercase d and lowercase j, and uppercase s represents the suffix of the date.


2, Hours: minutes: seconds

By default, the PHP interpretation is displayed as "Greenwich Mean Time", which differs from our local time by 8 hours.

The code is as follows Copy Code

echo Date (' g:i:s a ');

5:56:57 am

echo Date (' H:i:s A ');

05:56:57 AM

The lowercase g represents a 12-hour system without a leading 0, while the lowercase h indicates a 12-hour system with a leading 0.
When using the 12-hour system, it is necessary to indicate that in the afternoon, lowercase a represents the lowercase "am" and "PM", and uppercase a denotes uppercase "AM" and "PM".

The code is as follows Copy Code

echo Date (' g:i:s ');

14:02:26

1 2

http://www.bkjia.com/PHPjc/628995.html www.bkjia.com true http://www.bkjia.com/PHPjc/628995.html techarticle Let's look at some of the usage and basic details of the date () function in PHP, as you can see here. The Date function usage code follows the copy code date ($t); The format is as follows: The format of the display ...

  • 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.