How to convert PHP string into time: first create a PHP sample file; then define a variable "$temp_date"; finally pass "date('Y-m-d',strtotime($temp_date));" Just convert the string variable into time.
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
php string formatting into time
In normal times we often need to format the time of a string before using it
Php can use the following method:
$temp_date = '2011-01-09 19:25:43'; date('Y-m-d',strtotime($temp_date)); //这个的输出是 2011-01-09
The function of strtotime is-- Parse the date and time description of any English text into a UNIX timestamp
The following is the official description:
int strtotime ( string time [, int now])
This function is expected to accept a string containing an English date format and try to parse it into a UNIX timestamp. If the format of time is absolute time, the now parameter has no effect.
If the format of time is a relative time, the relative time is provided by now, or the current time is used if the now parameter is not provided. Returns -1 on failure.
The programs must be relatively robust, then we can judge whether they can be converted.
It should also be noted that this has a time interval: Friday, December 13, 1901 at 20:45 :54 Until Tuesday, January 19, 2038 03:14:07
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of How to convert php string to time. For more information, please follow other related articles on the PHP Chinese website!