php method to convert time into numbers: 1. Create a php sample file; 2. Define a time that needs to be converted; 3. Use the "strtotime('Y-m-d H:i:s');" method Just parse the time into numerical form.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
How to convert time into numbers in php ?
php numerical conversion time and time conversion numerical usage example
The code is as follows:
echo $startime=strtotime(date("Y-m-d",time()));//当天0点时间戳 echo "<br/>"; echo $endttime=strtotime(date("Y-m-d",time()).' 23:59:59');//当天23:59:59的INT类型时间戳 echo "<br/>"; //把数值型转成时间字符型 $dotime="1357985479"; echo date("Y-m-d H:i:s",$dotime);//把数字型时间按格式转换成时间格 echo "<br/>"; //输出当前时间字符串型 echo strtotime(date('Y-m-d H:i:s',time())); echo "<br/>"; //把数值型转成字符串型 echo date('Y-m-d H:i:s','1357985479'); echo "<br/>"; //把字符串型转成数值型 echo strtotime('Y-m-d H:i:s'); //echo "<br/>"; //最近七天 echo strtotime("-7 days")
The running results are as follows:
1495065600 1495151999 2013-01-12 10:11:19 1495073470 2013-01-12 10:11:19 1494468670
Related introduction:
The strtotime() function parses any English text date or time description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).
Note: If the year representation uses a two-digit format, values 0-69 will be mapped to 2000-2069, and values 70-100 will be mapped to 1970-2000.
Note: Please note that for dates in m/d/y or d-m-y format, if the separator is a slash (/), the American m/d/y format is used. If the delimiter is a dash (-) or a dot (.), the European d-m-y format is used. To avoid potential errors, you should use YYYY-MM-DD format whenever possible or use the date_create_from_format() function.
Syntax
strtotime(time,now);
Parameters
time Required. Specifies a date/time string.
now Optional. Specifies the timestamp used to calculate the return value. If this parameter is omitted, the current time is used.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert time into numbers in php. For more information, please follow other related articles on the PHP Chinese website!