亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據例外情況計算和調整日期 (PHP)

根據例外情況計算和調整日期 (PHP)

PHP
犯罪嫌疑人X 2023-11-03 17:41:51
規則如下:天數的添加始終為15 秒(例如 15、30、45、60 等)當到期日為15 日或月底(例如,30 或 31 取決于月份,每年 2 月 28 或 29 取決于閏年)時,添加天數(如上所述)時,日期應僅落在15 日或月底。當到期日不是每 15 日或月底時,通常只需添加天數。當日期為2 月 14 日并添加 15 天時,如果是閏年,則應返回02/29;如果不是閏年,則應返回 02/28。這是我的代碼,但是我收到 1 個錯誤和不一致。當日期為02/29/2020并添加30 天時,可捕獲致命錯誤。我可以做什么來適應這個規則?
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

function adjustDate($maturitydate, $add) {

    $nodays = '+'.$add.' days';

    $date = new DateTime($maturitydate);

    $matdt = $date->modify($nodays);

    $ismaturitydateendofmonth = check_end_of_month($maturitydate);


    if($date->format('d') == 15) {

        $matdt =  $matdt->format('m/15/Y');

    }

    else if($ismaturitydateendofmonth == '1'){

        $matdt->modify('last day of this month');

    }

    else{

        $matdt =  $matdt->format('m/d/Y');

    }

    

    return $matdt;

}


function check_end_of_month($date){

    //adds 1 day to date

    $Temp = date('m/d/Y',strtotime("+1 day", strtotime($date)));


    //get the month of each date

    $tempmonth = date('m', strtotime($Temp));

    $datemonth = date('m', strtotime($date));

    

    //check if the months are equal

    if($tempmonth != $datemonth){

        return '1';

    }

    else{

        return '0';

    }

}


查看完整回答
反對 回復 2023-11-03
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號