Provides various official and user-released code examples. For code reference, you are welcome to learn about the differences between the time (), date (), and mktime () functions of php.
Php: time (), date (), mktime () date and time function library {often forget}
Checkdate: Verify that the date is correct.
Date: format the server time.
Strftime: format the server time locally.
Getdate: Get the time and date information.
Gettimeofday: Get the current time.
Gmdate: Get the current time difference from GMT.
Easter_date: Calculate the Easter date.
Easter_days: calculates the number of days between Easter and January 1, lunar March 21.
Mktime: Obtain UNIX timestamps.
Gmmktime: returns the Greenwich Mean Time of UNIX timestamps.
Time: Obtain the UNIX timestamp of the current time.
Microtime: gets the UNIX timestamp value of one second per million at the current time.
Checkdate verifies the correctness of the date.
Syntax: int checkdate (int month, int day, int year );
Return Value: integer
Function Type: time and date
If the date is valid, true is returned. if the date is incorrect, false is returned. This function can be used to check whether the date is valid. The valid range is as follows:
The year is from 0 to 32767 years.
The month is from 1 to December.
The day changes with the month and the leap year.
Date Format the server time.
Syntax: string date (string format, int [timestamp]);
Return Value: String
Function Type: time and date
Description of returned values? The string is determined by the configured format. If a timestamp value is input, the timestamp is formatted and returned. If no timestamp value is input, the current server time is formatted and returned. To convert a date to another language format, use the setlocale () and strftime () functions. The options for string formatting are as follows:
A-"am" or "pm"
A-"AM" or "PM"
D-a few days, two digits. If there are less than two digits, fill in the first zero. For example, "01" to "31"
D-the day of the week, with three English letters, for example, "Fri"
F-month, full English name; for example: "January"
H-12 hours, for example, "01" to "12"
H-24 hours, for example, "00" to "23"
Hours in the g-12 hour format. Less than two hours do not fill in zero. For example: "1" to 12"
Hours in the G-24-hour format. Less than two hours do not fill in zero. For example: "0" to "23"
I-minutes; for example: "00" to "59"
J-a few days, two digits. If less than two digits are left blank, for example, "1" to "31"
L-the day of the week, full name in English; for example: "Friday"
M-month, two digits. If there are less than two digits, add zero in front, for example, "01" to "12"
N-month, two digits. If less than two digits are left blank, for example, "1" to "12"
M-month, with three English letters, for example, "Jan"
S-seconds; for example: "00" to "59"
The end of the S-character is followed by an English sequence, with two English letters, for example, "th", "nd"
T-specifies the number of days in a month, for example, "28" to "31"
U-total seconds
W-number of weeks, for example, "0" (Sunday) to "6" (Saturday)
Y-year, four digits, such as: "1999"
Y-year, two digits, for example, "99"
Z-the day of the year, for example, "0" to "365"
Other characters not in the upper column are listed directly.
Example 1:
print(date( "l dS of F Y h:i:s A" ));
print("July 1, 2000 is on a " . date("l", mktime(0,0,0,7,1,2000)));
?>
Example 2:
$tomorrow = mktime(0,0,0,date("m") ,date("d")+1,date("Y"));
$lastmonth = mktime(0,0,0,date("m")-1,date("d"), date("Y"));
$nextyear = mktime(0,0,0,date("m"), date("d", date("Y")+1);
?>
See gmdate () mktime ()
Strftime format the server time locally.
Syntax: string strftime (string format, int [timestamp]);
Return Value: String
Function Type: time and date
The content indicates that the returned value string is determined by the configuration format. If a timestamp value is input, the timestamp is formatted and returned. If no timestamp value is input, the current server time is formatted locally. The name of a month or week varies with the settings of setlocale () in the local language.
The returned string can be in the following format:
% A abbreviation of the day of the week.
% A full name of the day of the week.
The abbreviation of % B month name.
% B full name of the month name.
% C the local date time is better than the string.
% D indicates the day of the month (range: 00 to 31) with a number ).
% H indicates the hour in the 24-hour format (ranging from 00 to 23 ).
% I represents the hour in 12-hour format (range: 01 to 12 ).
% J indicates the day of the year (range: 001 to 366 ).
The number of % m months (ranging from 1 to 12 ).
% M minutes.
% P uses 'am' or 'pm 'to indicate the local time.
% S seconds.
% U indicates the week of the current year. The first week starts from the first Sunday.
% W indicates the week of the current year. The first week starts from the first Monday.
% W indicates the day of the week by number (0 indicates Sunday ).
% X date representation without time.
% X does not include the time representation of the date.
The two digits % y indicate the year (range: 00 to 99 ).
% Y indicates the complete year number, that is, the four-digit number.
% Z time zone or abbreviated name.
% Characters.
Example
setlocale ("LC_TIME", "C");
print(strftime("%A in Finnish is "));
setlocale ("LC_TIME", "fi");
print(strftime("%A, in French "));
setlocale ("LC_TIME", "fr");
print(strftime("%A and in German "));
setlocale ("LC_TIME", "de");
print(strftime("%A.n"));
?>
Reproduced original address: http://www.jb100.net/html/content-22-942-1.html
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB