PHP-time (), date (), mktime () date and time function library _ PHP Tutorial

Source: Internet
Author: User
Tags month name
PHP-time (), date (), mktime () date and time function library. Checkdate verifies the correctness of the date. Syntax: intcheckdate (intmonth, intday, intyear); return value: integer function type: time and date content description if the date is valid, the checkdate verification date is returned.
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. Valid range: Year 0 to 32767 years
The month is from 1 to December.
The date format of the server time varies with the month and the leap year.
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 "));
Print ("July 1, 2000 is on a". date ("l", mktime )));
?>

Example 2:
   $ Tomorrow = mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y "));
$ Lastmonth = mktime (0, 0, date ("m")-1, date ("d"), date ("Y "));
$ Nextyear = mktime (0, 0, 0, date ("m"), date ("d", date ("Y") + 1 );
?>

Refer to gmdate () mktime () strftime to 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 "));
?>
Refer to setlocale () mktime () getdate to obtain the time and date information.
Syntax: array getdate (int timestamp );
Returned value: Array
Function type: time and date
The returned array elements include the following items:
"Seconds"-seconds
"Minutes"-minute
"Hours"-Hour
"Mday"-the day of the month
"Wday"-number of the day of the week
"Mon"-number of months
"Year"-year, number
"Yday"-the number of the day of the current year, for example, "299"
"Weekday"-full name of the day of the week, for example, "Friday"
"Month"-full name of the month; for example, "January" gettimeofday gets the current time.
Syntax: array gettimeofday (void );
Returned value: Array
Function type: time and date
The returned array elements include the following items: "sec"-seconds
"Usec"-one minute per second
"Minuteswest"-Greenwich Mean Time score
"Dsttime"-the time difference between the current time zone gmdate and GMT.
Syntax: string gmdate (string format, int timestamp );
Return value: string
Function type: time and date
Content Description: This function is similar to the date () function. The difference is that this function returns an example of the Time used after the Time difference with the Greenwich Mean Time (GMT ).
   Echo date ("M d y h: I: s", mktime ));
Echo gmdate ("M d y h: I: s", mktime ));
?>
If the machine running this example is in Finland (Finland, GMT + 0200), the returned result is: Jan 01 1998 00:00:00
Dec 31 1997 22:00:00
Refer to date () mktime () gmmktime () easter_date to calculate the Easter date.
Syntax: int easter_date (int [year]);
Return value: integer
Function type: time and date
Description: If a year is input, the Easter date of the year is returned in UNIX time stamp format. if the year is not input, the date of the year is calculated. Value? Note that the input year must be between 1970 a.m. and 2037 a.m.; otherwise, it cannot be calculated. Example
   Echo date ("M-d-Y", easter_date (1999 ));
Echo date ("M-d-Y", easter_date (2000 ));
Echo date ("M-d-Y", easter_date (2001 ));
?>
The returned result is
Apr-04-1999
Apr-23-2000
Apr-15-2001 easter_days calculates the number of days between Easter and lunar March 21.
Syntax: int easter_days (int [year]);
Return value: integer
Function type: time and date
Description: If a year is input, the number of days between Easter and January 1, March 21 is calculated. if the year is not input, the current year is used. This function can be used to replace the issue that cannot be calculated beyond the range easter_date () 1970-2037. Example
   Echo easter_days (1999 );
Echo easter_days (1492 );
Echo easter_days (1913 );
?>
The returned result is:
14 (4/4)
32 (4/22)
2 (3/23)
Obtain UNIX timestamps by referring to easter_date () mktime.
Syntax: int mktime (int hour, int minute, int second, int month, int day, int year );
Return value: integer
Function type: time and date
Description: enter a time to return a long integer of UNIX timestamps. Example
   Echo date ("M-d-Y", mktime ));
Echo date ("M-d-Y", mktime ));
Echo date ("M-d-Y", mktime ));
?>
Refer to date () time () gmmktime to obtain the Greenwich mean time of UNIX timestamps.
Syntax: int gmmktime (int hour, int minute, int second, int month, int day, int year );
Return value: integer
Function type: time and date
Description: enter a time to return a long integer of the UNIX Greenwich mean time stamp. Time gets the UNIX timestamp of the current time.
Syntax: int time (void );
Return value: integer
Function type: time and date
The content description returns the stamp value of the current time.
Refer to date () microtime to get the UNIX time stamp of the current time, the value of one second per million.
Syntax: string microtime (void );
Return value: string
Function type: time and date
Description: returns the timestamp value of one million points per second of the current time. If the operating system does not provide the gettimeofday () system call function, this function is also invalid.

The http://www.bkjia.com/PHPjc/364166.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364166.htmlTechArticlecheckdate verifies the correctness of the date. Syntax: int checkdate (int month, int day, int year); return value: integer function type: Time date description: if the date is valid, return...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.