Re: [心得] 關於時間日期加減的方法
※ 引述《idcomputer (順)》之銘言:
: ※ 引述《arrack (艾瑞克)》之銘言:
: : mktime 會自動做出修正...
: : 不需要自己手動判斷...
: : Mktime(0,0,0,4,28+7,2008);
: : //自動轉成2008-05-05
: : 所以並沒有回應者所敘述的問題
: 想請問一下
: 如果知道某日~~
: EX 2008 4 28 (一)
: Mktime(0,0,0,4,28,2008);
: 想要將接下來的18周的禮拜一的日期挑出來存在陣列中
: 該怎麼去寫這個迴圈呢?!~~
sorry, 我找不到最原始的那篇, 所以隨便亂入一篇了..
比較直覺一點的方法, 2009-02-02 後的 18 個星期一:
<?php
$d = strtotime("2009-02-02");
for($i=1;$i<=18;$i++) {
echo date("Y-m-d",strtotime("+{$i} weeks",$d))."\n";
}
?>
執行 (我是在命令列執行的):
2009-02-09
2009-02-16
2009-02-23
2009-03-02
2009-03-09
2009-03-16
2009-03-23
2009-03-30
2009-04-06
2009-04-13
2009-04-20
2009-04-27
2009-05-04
2009-05-11
2009-05-18
2009-05-25
2009-06-01
2009-06-08
看一下 strtotime() 的說明:
int strtotime ( string $time [, int $now] )
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.166.139.145
※ 編輯: KC73 來自: 118.166.139.145 (01/31 15:38)
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章