The PHP strtotime () function resolves the date and time to a UNIX timestamp instance

Source: Internet
Author: User
In PHP we use the strotime () functionYou can resolve the date and time of any English text to a Unix timestamp. Its syntax is as follows:

Strotime () function syntax format

Strtotime (Time,now);

Its value is relative to the time given by the parameter now, and if this parameter is not present then the current time of the system is used.

Detailed parameters:

The function has two parameters

Time

The parsed string, formatted according to the syntax of the gnu» date input format. Before PHP 5.0, there were no milliseconds allowed in time, but could be omitted from PHP 5.0.

Now

The timestamp used to calculate the return value. The default value for this parameter is time () of the current time, or it can be set to a timestamp of another time ()

Return value: Success returns an inter-stamp, otherwise FALSE is returned. Before PHP 5.1.0, this function returns 1 on failure, and later returns false.

The first parameter of Strtotime can be our common English time format, such as "2008-8-20" or "Ten September 2000" and so on. It can also be a time description based on the parameter now, such as "+1 Day" and so on.

Strotime () Function instance

Instance One

Use the Strotime () function to get the UNIX timestamp for the specified date, as shown in the code

<?phpecho strtotime ("2017-4-10");? >

Operation Result:

Example Description: Return April 10, 2017 0:0 0 seconds timestamp


Example Two

This example applies the Strotime () function to obtain the UNIX timestamp of the English format date-time string, and outputs some time to the instance code as follows

<?phpheader ("Content-type:text/html;charset=utf-8");    Set the encoding echo strtotime ("Now"). ";                                              Timestamp of the current time echo "Output time:". Date ("Y-m-d h:i:s", Strtotime ("Now"). " <br/> ";        Output Current time echo strtotime ("2017"). " ";                                     Outputs the timestamp of the specified date echo "Output time:". Date ("Y-m-d h:i:s", Strtotime ("2017")). " <br/> ";        Outputs the time of the specified date echo strtotime ("+3 Day"). " ";                                           Output timestamp after three days of the current time echo "Enter the time after three days:". Date ("Y-m-d h:i:s", Strtotime ("+3 Day"). " <br/> "; Echo strtotime (" +1 Week ")." "; echo" outputs the time of the next week: ". Date (" Y-m-d h:i:s ", Strtotime (" +1 Week "))." <br/> "; Echo strtotime (" +1 Week 2 days 3 hours 4 seconds ")." <br/> "; Echo strtotime (" NEXT Thursday ")." <br/> "Echo strtotime (" last Monday ");? >

Code Run Result:

The

Above is the simple function that our strotime () function completes. In the next section, we'll take a few time functions that we learned earlier, have our mktime () function get the local timestamp, the time () function gets the current timestamp, the date () function gets the current date and time, the GETDATE () function Gets the date information and the Checkdate () function to verify the validity of dates, etc., through these functions, to complete our application of the date and time.

Related Article

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.