Home  >  Article  >  Backend Development  >  Detailed introduction to php’s date() function

Detailed introduction to php’s date() function

巴扎黑
巴扎黑Original
2016-11-24 14:38:181008browse

1, year-month-day
echo date('Y-m-j');
2007-02-6

echo date('y-n-j');
07-2-6

Capital Y means the fourth day of the year digits, while lowercase y represents the two-digit number of the year;
lowercase m represents the number of the month (with a leading), while lowercase n represents the number of the month without the leading. http://www.my400800.cn

echo date('Y-M-j');
2007-Feb-6

echo date('Y-m-d');
2007-02-06

Capital M means 3 abbreviation characters for the month, and lowercase m represents the number of the month (with leading 0);
There is no uppercase J, only lowercase j represents the date of the month, without the leading o; if the month needs to be preceded, use lowercase d.

echo date('Y-M-j');
2007-Feb-6

echo date('Y-F-jS');
2007-February-6th

Capital M represents the 3 abbreviation characters of the month, while uppercase 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 and lowercase y to represent the year;
You can use uppercase F, uppercase M, lowercase m and lowercase n to represent the month (two ways of representing characters and numbers respectively);
You can use lowercase letters to represent the day. d and lowercase j, 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');//Don’t treat the lowercase m as an ingredient here. I gave in to this mistake
05:56:57 AM

The lowercase g indicates the 12-hour format without leading 0, while the lowercase h indicates the 12-hour format with leading 0.
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 Number

Summary:
The letter g represents the hour without a leading, the letter h represents the hour with a leading;
lowercase g and h represent the 12-hour format, and capital 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 means to determine whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
Lowcase l means the full English version of the day of the week (Tuesday);
Use capital D to represent the day of the week The 3-character abbreviation of a few (Tue).

echo date('w');
Today's week: 2

echo date('W');
This week is the 06th week of the year

lowercase w represents the day of the week, and the number form represents
uppercase W Indicates the number of weeks in the year

echo date('t');
This month has 28 days

echo date('z');
Today is the 36th day of this year

lowercase t indicates the current month Day
lowercase z indicates the day of the year today

4, others

echo date('T');
UTC
uppercase T indicates the server's time zone setting

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, It is the UNIX timestamp of the Unix time epoch.

echo date('c');
2007-02-06T14:24:43+00:00
lowercase c represents ISO8601 date, the date format is YYYY-MM-DD, use the letter T to separate the date and time, time The 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 represents the RFC822 date.

Statement:
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