strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。
<code>strtotime(<span>time</span>,now)<span> //参数描述</span><span>time</span> 规定要解析的时间字符串。 now 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。</code>
该函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数,则用系统当前时间。
<code><?php <span>var_dump(<span>strtotime(<span>"now"</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>
运行结果如下
<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>
以上就介绍了PHP字符串解释成时间,加一天,加一个月等,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。