PHP中strtotime函數使用方法
一,獲取指定日期的unix時間戳
strtotime("2009-1-22") 示例如下:
strtotime("2009-1-22")
結果:1232553600
說明:返回2009年1月22日0點0分0秒時間戳
二,獲取英文文本日期時間
示例如下:
便於比較,使用date將當時間戳與指定時間戳轉換成系統時間
(1)打印明天此時的時間戳strtotime("+1 day")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("+1 day"))
結果:2009-01-23 09:40:25
(2)打印昨天此時的時間戳strtotime("-1 day")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("-1 day"))
結果:2009-01-21 09:40:25
(3)打印下個星期此時的時間戳strtotime("+1 week")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("+1 week"))
結果:2009-01-29 09:40:25
(4)打印上個星期此時的時間戳strtotime("-1 week")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("-1 week"))
結果:2009-01-15 09:40:25
(5)打印指定下星期幾的時間戳strtotime("next Thursday")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("next Thursday"))
結果:2009-01-29 00:00:00
(6)打印指定上星期幾的.時間戳strtotime("last Thursday")
當前時間:
date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
date("Y-m-d H:i:s",strtotime("last Thursday"))
結果:2009-01-15 00:00:00
以上示例可知,strtotime能將任何英文文本的日期時間描述解析爲Unix時間戳,我們結合mktime()或date()格式化日期時間獲取指定的時間戳,實現所需要的日期時間。
希望通過本文的介紹後,你已經能掌握strtotime函數用法。
相關文章
-
PHP中strtotime函數使用方法詳解
在PHP中有個叫做strtotime的函數。strtotime 實現功能:獲取某個日期的時間戳,或獲取某個時間的時間戳。strtotime 將任何英文文本的日期時間描述解析爲Unix時間戳[將系統時間轉化成unix時間戳]那麼,PHP中strtotime函數使 -
關於JavaScript中isPrototypeOf函數作用和使用實例
JavaScript中isPrototypeOf函數方法是返回一個布爾值,指出對象是否存在於另一個對象的原型鏈中。使用方法:代碼如下:ototypeOf(object2)其中object1爲必選項,一個對象的實例。object2爲必選項,另一個對象,將要檢查其原型 -
php強大的時間轉換函數strtotime
在php中strtotime() 函數將任何英文文本的日期時間描述解析爲 Unix 時間戳,這個函數也是我們經常會用到的`,有需要的朋友參考一下.使用strtotime可以將各種格式的時間字符串轉換爲時間戳 轉換常規時間格式?123echo d -
Zend studio for eclipse中使php可以調用mysql相關函數的設置方
Zend studio for eclipse中使php可以調用mysql相關函數的設置方法教程如果直接調用mysql_connect會出現:Fatal error: Call to undefined function mysql_connect() 的錯誤解決辦法,找到zend studio 所在的`位置我的zen -
Thinkpad筆記本開機顯示Tointerrruptnormalstartup解決方法
Thinkpad筆記本開機顯示To interrrupt normal startup的解決方法1、先等待5-6分鐘,如果系統又恢復了正常,說明可能是系統硬盤或者風扇區出了問題;2、假如過了5-6分鐘依然沒有反應,則可嘗試先拆掉筆記本電池在裝上;3、或 -
PowerPoint2007中SmartArt的使用方法
SmartArt是Microsoft Office 2007中新加入的特性,用戶可在PowerPoint,Word,Excel中使用該特性創建各種圖形圖表,下面是由本站小編爲大家整理的PowerPoint2007中SmartArt的使用方法,喜歡的'可以收藏一下!瞭解更多詳情資訊, -
有關PHP字符串比較函數strcmp()和strcasecmp()使用總結
比較字符串是任何編程語言的字符串處理功能中重要的特性之一。在PHP中除了可以使用比較運算符號(==、<或>)加以比較外,還提供了一系列的比較函數,使PHP可以進行更復雜的字符串比較。如strcmp()、strcasecmp()和statcmp() -
解決PHP中file-get-contents函數的方法
方法一:在php中,抓取https的`網站,提示如下的錯誤內容:Waing: file_get_contents() [-get-contents]: failed to open stream: Invalid argument in I: on line 16打開文件找到 ;extension=php_ ,去掉雙引號”;” ,重啓web -
PHP中使用cURL實現Get和Post請求的方法
在PHP的應用中,一定搞清楚Get和Post請求兩種方法是怎麼應用的,以下是本站小編精心爲大家整理的PHP中使用cURL實現Get和Post請求的方法,希望對大家使用cURL有所幫助!更多內容請關注應屆畢業生網! 介紹cURL 是一個利用U -
Efforts Urged to Improve Womens Reproductive Health英語閱讀
Efforts Urged to Improve Women's Reproductive HealthParliamentarians from over 100 countries are being urged to take action in improving women's reproductive health ahead of the 2015 deadline