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>; <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教程有興趣的朋友有所幫助。