0
我試圖爲每週的每一天生成時間戳。我的周開始星期一和結束太陽。PHP爲每週的每一天生成時間戳
我的代碼至今爲止如下。問題是,今天(星期六),生成的Sun時間戳是「上週日」,但應該是「下個星期日」。
我不知道什麼最好的方法是不使用if/else語句的負載。
$today = time();
//$today = strtotime('next monday');
// If today is monday, generate timestamps for each day of the week starting today
if(date('D', $today) == 'Mon') {
$mon = $today;
$tue = strtotime('next tuesday');
$wed = strtotime('next wednesday');
$thu = strtotime('next thursday');
$fri = strtotime('next friday');
$sat = strtotime('next saturday');
$sun = strtotime('next sunday');
}
// Today is not monday, so generate timestamps for each day of the week, starting last monday
else {
$mon = strtotime('last monday');
$tue = (date('D', $today) == 'Tue') ? $today : strtotime('last tuesday');
$wed = (date('D', $today) == 'Wed') ? $today : strtotime('last wednesday');
$thu = (date('D', $today) == 'Thu') ? $today : strtotime('last thursday');
$fri = (date('D', $today) == 'Fri') ? $today : strtotime('last friday');
$sat = (date('D', $today) == 'Sat') ? $today : strtotime('last saturday');
$sun = (date('D', $today) == 'Sun') ? $today : strtotime('last sunday');
}
'$週二= $今天+(60 * 60 *(1 * 24)); $ wed = $ today +(60 * 60 *(2 * 24));' –