In PHP, we use the strotime () function to parse the date and time of any English text into UNIX timestamps. Its syntax is as follows: we use
Strotime () functionThe date and time of any English text can be parsed into UNIX timestamps. Its syntax is as follows:
Strotime () function syntax format
strtotime(time,now);
The value is relative to the time given by the parameter now. if the parameter now is not provided, the current system time is used.
Parameters:
This function has two parameters.
Time
The parsed string, in the format of the syntax in the GNU» date input format. Before PHP 5.0, the number of milliseconds in time is not allowed. it may exist since PHP 5.0 but will be ignored.
Now
The timestamp used to calculate the return value. The default value of this parameter is the current time (). It can also be set to another time stamp ()
Return value: the timestamp is returned if the request is successful. otherwise, FALSE is returned. Before PHP 5.1.0, this function returns-1 if it fails, and false if it is later.
The first parameter of strtotime can be a common English time format, such as "" or "10 September 2000. You can also describe the time based on the parameter now, such as "+ 1 day.
Strotime () function instance
Instance 1
Use the strotime () function to obtain the unix timestamp of the specified date. The code is as follows:
Running result:
Instance 2
In this example, the strotime () function is used to obtain the UNIX timestamp of a date string in English format, and some time is output. the instance code is as follows:
"; // Output current time echo strtotime (" 10 May 2017 "). ""; // output the timestamp echo of the specified date "output Time :". date ("Y-m-d H: I: s", strtotime ("10 May 2017 "))."
"; // Output the time of the specified date echo strtotime (" + 3 day "). ""; // output the timestamp echo of the current time after three days "input the time after three days :". date ("Y-m-d H: I: s", strtotime ("+ 3 day "))."
"; Echo strtotime (" + 1 week "). ""; echo "output time of the next week :". date ("Y-m-d H: I: s", strtotime ("+ 1 week "))."
"; Echo strtotime (" + 1 week 2 days 3 hours 4 seconds ")."
"; Echo strtotime (" NEXT Thursday ")."
"; Echo strtotime (" last Monday ") ;?>
Code running result:
The above is a simple function completed by the strotime () function. In the next section, we will use the time functions we learned earlier to obtain the local timestamp through our mktime () function, and the time () function to obtain the current timestamp, date () the function obtains the current date and time. the getdate () function obtains the date information and the checkdate () function checks the validity of the date. through these functions, we can apply the date and time.
The above is the detailed description of the php strtotime () function that parses the date and time into a UNIX timestamp instance. For more information, see other related articles in the first PHP community!