0
我想在當前月份和上個月之後的2個月後查找。我編碼如下,找到下個月,上個月給出錯誤結果
$current = strtotime(date('m',time()) . '-01 00:00:01');
$next_month = date('m', strtotime('+1 month', $current));
$next_next_month = date('m', strtotime('+2 month', $current));
$previous_month = date('m', strtotime('-0 month', $current));
echo $previous_month.$next_month.$next_next_month;
output : 01 02 03
我想從當前月份得到結果。預期產出是04 05 06
。
如何實現這個結果。有沒有解決辦法。謝謝。
這可能是因爲你沒有使用'$ current'一年,你有沒有試過'$ current = strtotime(date('Y-m')。'-01 00:00:01');'?沒有一年,這可能是一個無效的日期。 '$ current'的價值是什麼?另外,我認爲'$ previous_month'應該使用'-1月'而不是'-0'。 – rickdenhaan
@rickdenhaan:謝謝你。這樣可行。 –