PHP Date and Time function library

Source: Internet
Author: User
Tags echo date local time sunrise time

Function

Describe

Checkdate ()

Verify the Gregorian date.

Date_default_timezone_get ()

Returns the default time zone.

Date_default_timezone_set ()

Set the default time zone.

Date_sunrise ()

Returns the sunrise time for a given date and place.

Date_sunset ()

Returns the sunset time for a given date and place.

Date ()

Format local time/date.

GETDATE ()

Returns the date/time information.

Gettimeofday ()

Returns the current time information.

Gmdate ()

Format GMT/UTC Date/time.

Gmmktime ()

Gets the UNIX timestamp for the GMT date.

Gmstrftime ()

GMT/UTC Time/date is formatted according to local locale settings.

Idate ()

Format local time/date as an integer

LocalTime ()

Returns the local time.

Microtime ()

Returns the number of microseconds for the current time.

Mktime ()

Returns a Unix timestamp for a date.

Strftime ()

Formats local time/date according to locale.

Strptime ()

Resolves the date/time generated by strftime.

Strtotime ()

Resolves the date or time description of any English text to a Unix timestamp.

Time ()

Returns the Unix timestamp for the current time.

Strtotime function

The function resolves the datetime description of any English text to a Unix timestamp.

One, the PHP timestamp function gets the UNIX timestamp for the specified date

Examples are as follows:

Echo strtotime ("2009-1-22″) Results: 1232553600

Description: Return January 22, 2009 0:0 0 seconds timestamp

Second, PHP timestamp function get English text date time

Examples are as follows:

Easy to compare, use date to convert time stamp to system time with specified timestamp

(1) Print the timestamp for tomorrow at this time Strtotime ("+1 Day")

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25

(2) Print the timestamp at this time yesterday Strtotime ("-1 day")

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 day") Results: 2009-01-21 09:40:25

(3) Print timestamp strtotime ("+1 Week") at this time next week

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2009-01-29 09:40:25

(4) Print timestamp strtotime ("1 week") at this time last week

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 Week") Results: 2009-01-15 09:40:25

(5) Print the time stamp specified next week strtotime ("next Thursday")

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2009-01-29 00:00:00

(6) Print the timestamp strtotime ("last Thursday") specified on the previous day of the week

Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday")) Results: 2009-01-15 00:00:00

The PHP timestamp Function example above shows that Strtotime can parse the datetime description of any English text into a Unix timestamp, and we get the specified timestamp by combining mktime () or date () format date time to achieve the required date time.

PHP Date and Time function library

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.