Home > Backend Development > PHP Tutorial > PHP string is interpreted as time, add one day, add one month, etc.

PHP string is interpreted as time, add one day, add one month, etc.

WBOY
Release: 2016-07-29 09:06:53
Original
1460 people have browsed it

The

strtotime() function parses any English text datetime description into a Unix timestamp.

<code>strtotime(<span>time</span>,now)<span>
//参数描述</span><span>time</span> 规定要解析的时间字符串。
now 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。</code>
Copy after login

This function expects a string containing a US English date format and attempts to parse it into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT) with the value given relative to the now argument time. If this parameter is not provided, the current system time is used.

<code><?php
<span>var_dump(<span>strtotime(<span>"now"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"3 October 2005"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"+5 hours"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"+1 week"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"+1 week 3 days 7 hours 5 seconds"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"next Monday"</span>)</span>)</span>;
<span>var_dump(<span>strtotime(<span>"last Sunday"</span>)</span>)</span>;
<span>var_dump(<span>"今天:"</span>.<span>date(<span>'Y-m-d H:i:s'</span>)</span>)</span>;
<span>var_dump( <span>"明天:"</span>.<span>date(<span>'Y-m-d H:i:s'</span>,<span>strtotime(<span>'+1 day'</span>)</span>)</span>)</span>;
?></code>
Copy after login

The running results are as follows

<code><span>int</span>(<span>1452653589</span>)
<span>int</span>(<span>1128268800</span>)
<span>int</span>(<span>1452671589</span>)
<span>int</span>(<span>1453258389</span>)
<span>int</span>(<span>1453542794</span>)
<span>int</span>(<span>1453046400</span>)
<span>int</span>(<span>1452355200</span>)
<span>string</span>(<span>26</span>) <span>"今天:2016-01-13 10:53:09"</span><span>string</span>(<span>26</span>) <span>"明天:2016-01-14 10:53:09"</span></code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the interpretation of PHP strings into time, adding one day, adding one month, etc., including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template