Home > Backend Development > PHP Tutorial > How to use date and time functions in PHP

How to use date and time functions in PHP

WBOY
Release: 2016-07-25 08:53:11
Original
1411 people have browsed it
This article introduces the specific usage of date and time functions in php. Interested friends can refer to it.

Mainly introduces the usage of date and time functions such as date, getdate, mktime, and checkdate. (1)date usage: date(format,[time]); If there is no time parameter, the current time is used. The format is a string in which the following characters have special meaning: U is replaced by the number of seconds since a starting time (like January 1, 1970) Y is replaced with a 4-digit year number. y is replaced with a 2-digit year number. Replace F with the full English name of the month. M is replaced with the English abbreviation of the month. m is replaced with the number of months. Replace z with the number of days since January 1 of the current year. d is replaced with the number of days. l Replace with the full English name of the day of the week. D is replaced by the English abbreviation of the day of the week. w is replaced by the day of the week (number). H is replaced with the number of hours (24-hour clock). h is replaced by the number of hours (12-hour clock). i is replaced with minutes. s is replaced by seconds. Replace A with "AM" or "PM". Replace a with "am" or "pm". S is replaced with an ordinal suffix, such as: "st", "nd", "rd", "th". The function returns the replaced format string.

(2)getdate(time) Returns a hash table, each subscript is:

"seconds" -- number of seconds "minutes" -- fractions "hours" -- number of hours "mday" -- day number "mon" -- number of months "year" -- year number "yday" -- the number of days since January 1 "weekday" -- day of the week, full English name "month" -- month, full English name

(3)gmdate Similar to date, but first convert the time to Greenwich Mean Time.

(4)mktime usage: mktime(hours, minutes, seconds, months, days, years); Returns a time value that can be used in other functions.

(5)time usage: time(); Returns the number of seconds since midnight on January 1, 1970.

(6)microtime usage: microtime(); Returns a string, divided into two parts with spaces, the latter part is equivalent to time() The return value of , the first part is the number of microseconds.

(7)checkdate usage: checkdate(month, day, year); Returns logical true or logical false. if: [1] The year is between 1900 and 32767 (including 1900 and 32767); [2]The month is between 1 and 12; [3] The day is within the allowed number of days in the month (leap years are taken into account); then returns logical true.

(8)set_time_limit usage: set_time_limit(seconds); It stipulates that the program must run to completion within the specified number of seconds from the time this sentence is run. If it times out, the program will error and exit.



Related labels:
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