Home > Backend Development > PHP Tutorial > PHP Date() function detailed parameters

PHP Date() function detailed parameters

巴扎黑
Release: 2023-03-03 11:54:02
Original
1319 people have browsed it

Add
date_default_timezone_set(PRC) to the front page of the page; /*Adjust the time to Beijing time, php5 defaults to Greenwich Mean Time*/
date ()
a: "am" or "pm"
A : "AM" or "PM"
d: Day, two digits, zero if missing; from "01" to "31"
D: Day of the week, 3 English letters, such as: "Fri"
F: Month, full English name, such as: "January"
h: Hours in 12-hour format, from "01" to "12"
H: Hours in 24-hour format, from "00" to "23"
g: Hours in the 12-hour format do not add zeros; from "1" to "12"
G: Hours in the 24-hour format do not add zeros; from "0" to "23"
j: Days, any gaps will not be offset by zeros; From "1" to "31"
l: Day of the week, full English name, such as: "Friday"
m: Month, two digits, from "01" to "12"
n: Month, two digits, not Fill in zeros; from "1" to "12"
M: Month, 3 English letters; such as: "Jan"
s: Seconds; from "00" to "59"
S: Add an English ordinal at the end of the word, two English letters, such as: "21th"
t: The number of days in the specified month, from "28" to "31"
U: The total number of seconds
w: The numeric day of the week, from "0 (Sunday)" to "6 ( Saturday)"
Y: Year, four digits
y: Year, two digits
z: Day of the year; from "1" to "366"
============ ================================================== =====
1, year-month-day
indicates the year with uppercase Y and lowercase y;
indicates the month with uppercase F, uppercase M, lowercase m and lowercase n (representing two types of characters and numbers respectively) Method);
can use lowercase d and lowercase j to represent the day, and uppercase S represents the suffix of the date.
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 digits of the year digits;
lowercase m represents the number of the month (with leading), while lowercase n represents the number of the month without the leading.
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 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 capital F represents the month written in full English. (No lowercase f)
Capital S represents the suffix of the date, such as "st", "nd", "rd" and "th", depending on the date number.
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
lowercase g represents the 12-hour clock, There is no leading 0, and the lowercase h represents the 12-hour clock 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
Summary:
The letter g represents the hour without a leading, and 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 3-character day of the week Abbreviation (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, in numerical form
Capital W represents the year The number of the week in
echo date('t');
This month has 28 days
echo date('z');
Today is the 36th day of this year
lowercase t represents the number of days in the current month
lowercase z represents the day of the year today
4, others
echo date('T');
UTC
uppercase T represents the server time Regional settings
echo date('I');
0
Capital I means to determine whether it is daylight saving time, if true, return 1, otherwise 0
echo date('U');
1170769424
Capital U means since 1970 The total number of seconds from January 1st to now 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, use the letter T to separate the date and time, the time format For HH:MM:SS, the time zone is expressed as an offset from Greenwich Mean Time (GMT).
echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000
lowercase r represents the RFC822 date.
5. Format time
echo $row["t_time"]; will output 2008-2-29 12:08:00
echo date("Y-m-d",strtotime($row["t_time"])); will output 2008-2-29
Note, since the time obtained by $row["t_time"] is already a string, you need to use strtotime (string to timestamp) to convert it, otherwise the error of 1970-01-01 will be output

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