Home > Backend Development > PHP Tutorial > Detailed explanation of PHP's date and time function date()_PHP tutorial

Detailed explanation of PHP's date and time function date()_PHP tutorial

WBOY
Release: 2016-07-14 10:09:20
Original
883 people have browsed it

PHP date and time function date()

1, year-month-day
echo date('Y-m-j');
2007-02-6
echo date('y-n-j');
07-2-6
Capital Y represents the four-digit year, while lowercase y represents the two-digit year;
A lowercase m represents the number of the month (with a leading character), while a lowercase n represents the number of the month without a leading character.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-m-d');
2007-02-06
Capital M represents the 3 abbreviated characters of the month, while lowercase m represents the number of the month (with leading 0);
There is no capital J, only lowercase j represents the date of the month, without the leading o; if the month needs to be preceded, use the lowercase d.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-F-jS');
2007-February-6th
Capital M represents the 3 abbreviated characters of the month, while capital F represents the full English version 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;
The month can be represented by uppercase F, uppercase M, lowercase m and lowercase n (two ways to represent characters and numbers respectively);
can use lowercase d and lowercase j to represent the day, and uppercase S represents the suffix of the date.
2, hours: minutes: seconds
By default, the time displayed by PHP interpretation is "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 format without leading 0s, while a lowercase h indicates a 12-hour format with leading 0s.
When using the 12-hour clock, you need 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 the 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 clock, and uppercase G and H represent the 24-hour clock.
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);
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 number represents it
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 the day of the year today is
4, other
echo date('T');
UTC
Capital T indicates 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
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');
2007-02-06T14:24:43+00:00
Lowercase c represents the 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. 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/477675.htmlTechArticlePHP’s date and time function date() 1, year-month-day echo date(Y-m-j); 2007-02 -6 echo date(y-n-j); 07-2-6 Uppercase Y represents the four-digit year, while lowercase y represents the two-digit year; lowercase m represents the month...
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