- <pre name="code" class="php"><?php
- header("Content-type: text/html; charset=utf-8");
- echo '當前時間加一個月,一個禮拜,一天,一小時,15分鐘這裏測試';
- echo '<br>';
- echo '當前時間是'.date('Y-m-d H:i:s',time());
- $now = date('Y-m-d H:i:s',time());
- echo '<br>';
- echo '當前時間加長期這裏就加10年吧是:'. date("Y-m-d H:i:s",strtotime("+10years",strtotime($now)));
- echo '<br>';
- echo '當前時間加一年是:'. date("Y-m-d H:i:s",strtotime("+1years",strtotime($now)));
- echo '<br>';
- echo '當前時間加一月是:'. date("Y-m-d H:i:s",strtotime("+1months",strtotime($now)));
- echo '<br>';
- echo '當前時間加一週是:'. date("Y-m-d H:i:s",strtotime("+7days",strtotime($now)));
- echo '<br>';
- echo '當前時間加一週是:'. date("Y-m-d H:i:s",strtotime("+1weeks",strtotime($now)));
- echo '<br>';
- echo '當前時間加1小時是:'. date("Y-m-d H:i:s",strtotime("+1hours",strtotime($now)));
- echo '<br>';
- echo '當前時間加15分鐘是:'. date("Y-m-d H:i:s",strtotime("+15minutes",strtotime($now)));
- echo '<br>';
- echo '當前時間加1分鐘是:'. date("Y-m-d H:i:s",strtotime("+1minutes",strtotime($now)));
- echo '<br>';
- //時間比較,轉成時間戳
- //假如有效時間是1小時
- $nowtime = strtotime("now"); //或者 $nowtime = data('Y-m-d H:i:s',time());
- $endtime = strtotime(date("Y-m-d H:i:s",strtotime("+1hours",strtotime($now))));
- print_r($nowtime);
- echo '<br>';
- print_r($endtime);
- echo '<br>';
- echo '從而可以比較2兩時間來判斷是否執行某個時間';
php獲取當前時間,計算一天,一週,一月,一年後的時間
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.