Home >Backend Development >PHP Tutorial >Detailed explanation of the use of PHP date and time function date()_PHP tutorial
Date and time functions are a core component of PHP. No installation is required to use these functions. Let’s talk about the specific usage of date function in detail:
PHP Date() function
PHP Date() function can format the timestamp into a more readable date and time.
Syntax
date(format,timestamp)
format required. Specifies the format of the timestamp.
timestamp optional. Specify timestamp. The default is the current date and time.
PHP’s date and time function date()
The format of the first parameter respectively represents:
a - "am" or "pm"
A - "AM" or "PM"
d - day, two digits, If there are less than two digits, add zeros in front; such as: "01" to "31"
D - day of the week, three English letters; such as: "Fri"
F - month, full English name; such as: " January"
h - hour in 12-hour format; such as: "01" to "12"
H - hour in 24-hour format; such as: "00" to "23"
g - 12-hour format For hours in 24-hour format, do not add zeros if there are less than two digits; for example: "1" to 12"
G - For hours in 24-hour format, do not add zeros if there are less than two digits; for example: "0" to "23"
i - Minutes; such as: "00" to "59"
j - day, two digits, if there are less than two digits, do not add zero; such as: "1" to "31"
l - day of the week, in English name; such as: "Friday"
m - month, two digits, if less than two digits, add zeros in front; such as: "01" to "12"
n - month, two digits, if less than two digits If two digits are used, zeros will not be added; such as: "1" to "12"
M - month, three English letters; such as: "Jan"
s - second; such as: "00" to "59"
S - add an English ordinal number at the end of the word, two English letters; such as: "th", "nd"
t - specify the number of days in the month; such as: "28" to "31"
U - total seconds Number
w - numeric day 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 of the year; such as: "0" to "365"
Other characters not listed above will be listed directly
1, year-month-day
Capital M represents the 3 abbreviation 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 leading o; if the month is required Use a lowercase d when leading.
Capital M represents the 3 abbreviated characters of the month, while capital F represents the full English character 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:
can be represented by uppercase Y and lowercase y;
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, hour:minute:second
By default, the time displayed by PHP interpretation is "Greenwich Mean Time", which is 8 hours different from our local time.
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".
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 hour without leading , the letter h represents the hour with 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
Capital L means to determine whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
Lowercase l represents 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).
Today’s week: 2
This week is the 06th week of the year
The lowercase w represents the day of the week, expressed in numeric form
The uppercase W represents the number of weeks in the year
This month is 28 days
Today is the 36th day of the year
Lowercase t represents the number of days in the current month
Lowercase z represents the day of the year today
4, others
Capital T indicates the server’s time locale
Capital I means to determine whether the current daylight saving time is, if true, return 1, otherwise 0
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.
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). .
Lowercase r indicates RFC822 date.