How to use the date and time functions in PHP

Source: Internet
Author: User
Tags current time

(1) Date

Usage:

Date (format, [time]);

If there is no time argument, the current time is used.

A format is a string in which the following characters have special meaning:

U replaces the number of seconds since a start time (as if it were January 1, 1970)

Y replaces the 4-digit reign.

Y replaces the 2-digit reign.

F replaces the full name of the month in English.

M replaces the English abbreviation of the month.

M replaces the number of months.

Z replaces the number of days since January 1 of the year.

D replaces the number of own.

L REPLACE the English full name of the week.

D replaces the English abbreviation of the day of the week.

W replaces the Day of the Week (number).

H replaces the number of hours (24-hour system).

H replaces the number of hours (12-hour system).

I replace the number of minutes.

s replaces the number of seconds.

A Replace with "AM" or "PM".

A replace with "AM" or "PM".

S replaces the ordinal number suffix, for example: "St", "nd", "rd", "th".

function returns a format string that has been replaced.

(2) getdate (time)

Returns a hash table, each subscript is:

"Seconds"-number of seconds

"Minutes"--fractions

"Hours"--Number of hours

"Mday"--Number of days

"Mon"--Number of months

"Year"--the reign of the year

"Yday"--number of days since January 1

"Weekday"--day of the week, English full name

"Month"--month, full name in English

(3) Gmdate

Similar to date, but first converts time to Greenwich standard.

(4) Mktime

Usage:

Mktime (hours, fractions, seconds, months, days, years);

Returns a time value that can be used for other functions.

(5) Time

Usage:

Time ();

Returns the number of seconds since Horizon January 1, 1970.

(6) Microtime

Usage:

Microtime ();

Returns a string that is divided into two parts with a space, and the latter part equals time ()

Return value, 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 between 1900 and 32767 (including 1900 with 32767);

[2] The month between 1 to 12;

[3] The day is within the allowable number of days of the month (considering a leap year);

Returns the logic true.

(8) Set_time_limit

Usage:

Set_time_limit (number of seconds);

Specifies that the program must run at the end of a specified number of seconds from the time the sentence is run.

Timeout, the program is out of error.

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.