PHP code to display date and time_PHP tutorial

WBOY
Release: 2016-07-13 17:53:16
Original
1699 people have browsed it

PHP’s time display code is much more powerful than ASP, and it is simpler to call.
1. Year-month-day
echo date('Y-m-j');
2012-02-6
echo date('y-n-j');
07-2-6
An uppercase Y represents a four-digit year, while a lowercase y represents a two-digit year;
Lowercase m represents the number of the month (with a leading), while lowercase n represents the number of the month without the leading.

echo date('Y-M-j');
2012-Feb-6
echo date('Y-m-d');
2012-02-06
Uppercase M represents the 3 abbreviated characters of the month, while lowercase m represents the number of the month (with leading 0);
There is no uppercase J, only lowercase j represents the day of the month, without the leading o; if a leading month is required, use a lowercase d.
echo date('Y-M-j');
2012-Feb-6
echo date('Y-F-jS');
2012-February-6th
Capital M represents the 3 abbreviated characters of the month, while capital F represents the full English letter of the month. (no lowercase f)
Capital S represents the suffix of the date, such as "st", "nd", "rd" and "th", depending on the date number.

Summary:
You can use uppercase Y or lowercase y to indicate the year;
Months can be represented by uppercase F, uppercase M, lowercase m and lowercase n (two ways to represent characters and numbers respectively);
Lowercase d and lowercase j can be used to represent the day, and uppercase S represents the suffix of the date.

2. Hour:minute:second
By default, PHP interprets the displayed time as "Greenwich Mean Time", which is 8 hours different from our local time.
echo date('g:i:s a');
5:56:57 am
echo date('h:i:s A');
05:56:57 AM
A lowercase g indicates a 12-hour clock without leading 0s, while a lowercase h indicates a 12-hour clock with leading 0s.
When using the 12-hour clock, it is necessary to indicate morning and afternoon. Lowercase a represents lowercase "am" and "pm", and uppercase A represents uppercase "AM" and "PM".

echo date('G:i:s');
14:02:26
Capital G represents the hour in 24-hour format, but without leading; use capital H to represent hour in 24-hour format with leading
Summary:
The letter g represents the hour without leading, and the letter h represents the hour with leading;
Lowercase g and h represent the 12-hour format, while uppercase G and H represent the 24-hour format.

3. Leap year, week, day
echo date('L');
Whether this year is a leap year: 0

echo date('l');
Today is: Tuesday
echo date('D');
Today is: Tue
Capital L indicates whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
The lowercase l represents the full English word for the day of the week (Tuesday);
Instead, use a capital D to represent the 3-character abbreviation of the day of the week (Tue).

echo date('w');
Today’s week: 2
echo date('W');
This week is week 06 of the year
The lowercase w represents the day of the week, and the numeric form represents
Capital W represents the number of weeks in the year

echo date('t');
This month is 28 days
echo date('z');
Today is the 36th day of the year
Lowercase t represents the number of days in the current month
Lowercase z indicates what day of the year today is

4. Others
echo date('T');
UTC
A capital T represents the server’s time locale

echo date('I');
0
Capital I means to determine whether the current daylight saving time is, if true, return 1, otherwise 0

echo date('U');
1170769424
A capital U represents the total number of seconds from January 1, 1970 to the present, which is the UNIX timestamp of the Unix time epoch.

echo date('c');
2012-02-06T14:24:43+00:00
Lowercase c represents an ISO8601 date, the date format is YYYY-MM-DD, the letter T is used to separate the date and time, the time format is HH:MM:SS, and the time zone is represented by the offset from Greenwich Mean Time (GMT).

echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000
Lowercase r indicates RFC822 date

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478045.htmlTechArticlePHP’s time display code is much more powerful than ASP, and it is easier to call. 1. Year-month-day echo date(Y-m-j); 2012-02-6 echo date(y-n-j); 07-2-6 Capital Y represents the four-digit year...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template