Home  >  Article  >  Backend Development  >  How to convert time into numbers in php

How to convert time into numbers in php

藏色散人
藏色散人Original
2023-02-21 09:25:363576browse

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.

How to convert time into numbers in php

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()).&#39; 23:59:59&#39;);//当天23:59:59的INT类型时间戳
echo "<br/>";
//把数值型转成时间字符型
$dotime="1357985479";
echo date("Y-m-d H:i:s",$dotime);//把数字型时间按格式转换成时间格
echo "<br/>";
//输出当前时间字符串型
echo strtotime(date(&#39;Y-m-d H:i:s&#39;,time()));
echo "<br/>";
//把数值型转成字符串型
echo date(&#39;Y-m-d H:i:s&#39;,&#39;1357985479&#39;);
echo "<br/>";
//把字符串型转成数值型
echo strtotime(&#39;Y-m-d H:i:s&#39;);
//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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn