strtotime 函式應用

2021-07-10 12:58:56 字數 588 閱讀 2500

php中有乙個非常厲害的函式,strtotime()函式,這個函式有乙個異常厲害的使用方法,手冊上說的有,但是估計在實際應用中能夠想到的人不多。

我為了計算出當前時間n天後的日期時,也是自己寫了乙個很複雜的函式之後才無意間發現這個函式的,現在記錄下來以免以後又忘記了

然後舉一反三,乙個月之後呢?應該是strtotime(」+1 months」);

5天之後的時間呢當然是:strtotime(」+5 days」);

12個小時之後呢?strtotime(」+12 hours」);

20分鐘之後當然是:strtotime(」+20 minutes」);

30秒之後就是strtotime(」+30 seconds」);

上週六的時間呢?應該是 strtotime(」last  saturday「);

下週六當然是strtotime(」next saturday」);了

date(」y-m-d h:i:s」,strtotime(」+1 months +1 week +3 days +4 hours +16 minutes +32 seconds」));

當前時間之後的時間是「+」,之前的時間當然用「-」就可以了!

時間函式strtotime

1 列印明天此時的時間 strtotime 1 day 4echo date y m d h i s strtotime 1 day 5echo 67 列印昨天此時的時間 strtotime 1 day 8echo date y m d h i s strtotime 1 day 9echo 101...

PHP的時間函式strtotime

時間加減 php view plain copy 獲取本地提取年份 1 date date y m d mktime 0,0,0,date m date d date y 1 如果要獲取資料庫中的時間應該如何處理呢?在php文件中找到了乙個很好的函式strtotime,可以對時間進行加減 php v...

PHP函式strtotime 理解筆記

官方手冊裡面對strtotime的描述 strtotime 函式將任何英文文字的日期時間描述解析為 unix 時間戳。那麼意味著這個函式可以把2010 02 28 18 31 33轉換為1267353093這種格式 但是使用它轉換時間戳的時候要注意的是伺服器的date.timezone的配置,在函式...