一段搞不清其羅輯的程式 誰能幫我看一下~(date) |
尚未結案
|
e_snare
一般會員 發表:26 回覆:35 積分:12 註冊:2004-03-14 發送簡訊給我 |
此為計算某個日期加數天後的日期,純碎手工計算,不使用相關元件來計算!
紅色部份while(iInputDays>=28),算一整年會錯,例如1.31加365天
紅色部份while(iInputDays>=31),算一到二月會出錯,例如1.31加30天
__int32 iInputDays; AnsiString iInputStr; iUserYear = StrToInt(FormUI->DateTimePicker2->Date.FormatString("yyyy")); iUserMonth = StrToInt(FormUI->DateTimePicker2->Date.FormatString("mm")); iUserDay = StrToInt(FormUI->DateTimePicker2->Date.FormatString("dd")); iInputStr = FormUI->InputEDIT->Text; iInputDays = StrToInt(iInputStr); while(iInputDays>=365) { if(iInputDays>=366&&(iUserYear%4==0&&(iUserYear0!=0||iUserYear@0==0))) { iInputDays-=366; iUserYear ; } else { iInputDays-=365; iUserYear ; } } while(iInputDays>=28) //while(iInputDays>=31) { if(iUserMonth==1||iUserMonth==3||iUserMonth==5||iUserMonth==7||iUserMonth==8||iUserMonth==10||iUserMonth==12) { iInputDays-=31; iUserMonth ; } else if(iUserMonth==2) { if((iUserYear%4==0&&(iUserYear0!=0||iUserYear@0==0))) { if(iInputDays>=29) { iInputDays-=29; iUserMonth ; } else { iInputDays-=28; iUserMonth ; iUserDay--; } } else { iInputDays-=28; iUserMonth ; } } else if((iUserMonth==4)||(iUserMonth==6)||(iUserMonth==9)||(iUserMonth==11)&&iInputDays>=30) { iInputDays-=30; iUserMonth ; } else break; if(iUserMonth>12) { iUserMonth = 1; iUserYear ; } } iUserDay =iInputDays; if((iUserMonth==1)||(iUserMonth==3)||(iUserMonth==5)||(iUserMonth==7)||(iUserMonth==8)||(iUserMonth==10)||(iUserMonth==12)&&iUserDay>31) { iUserDay-=31; iUserMonth ; } else if(iUserMonth==2&&iUserDay>28) { if((iUserYear%4==0&&(iUserYear0!=0||iUserYear@0==0))) { if(iUserDay>29) { iUserDay-=29; iUserMonth ; } else exit; } else { iUserDay-=28; iUserMonth ; } } else if((iUserMonth==4)||(iUserMonth==6)||(iUserMonth==9)||(iUserMonth==11)&&iUserDay>30) { iUserDay-=30; iUserMonth ; } if(iUserMonth>12) { iUserMonth = 1; iUserYear ; } FormUI->DateTimePicker3->DateTime = StrToDateTime(Format("%d/%d/%d", ARRAYOFCONST((iUserYear, iUserMonth, iUserDay)))); |
e_snare
一般會員 發表:26 回覆:35 積分:12 註冊:2004-03-14 發送簡訊給我 |
這個是我算數天"前"的部份,目前沒發現問題,有需要的可以拿去參考參考,
有錯也請post出來讓大家知道,謝謝!
__int32 iInputDays; AnsiString iInputStr; iUserYear = StrToInt(FormUI->DateTimePicker2->Date.FormatString("yyyy")); iUserMonth = StrToInt(FormUI->DateTimePicker2->Date.FormatString("mm")); iUserDay = StrToInt(FormUI->DateTimePicker2->Date.FormatString("dd")); iInputStr = FormUI->InputEDIT->Text; iInputDays = StrToInt(iInputStr); if(iInputDays < 0) iInputDays = -iInputDays; while(iInputDays>=365) { if(iInputDays>=366&&((iUserYear-1)%4==0&&((iUserYear-1)0!=0||(iUserYear-1)@0==0))) { iInputDays-=366; iUserYear--; } else { iInputDays-=365; iUserYear--; } } while(iInputDays>=31) { if((iUserMonth-1)==1||(iUserMonth-1)==3||(iUserMonth-1)==5||(iUserMonth-1)==7||(iUserMonth-1)==8||(iUserMonth-1)==10||(iUserMonth-1)==0) { iInputDays-=31; iUserMonth--; } else if((iUserMonth-1)==2) { if((iUserYear%4==0&&(iUserYear0!=0||iUserYear@0==0))) { if(iInputDays>=29) { iInputDays-=29; iUserMonth--; } else { iInputDays-=28; iUserMonth--; iUserDay ; } } else { iInputDays-=28; iUserMonth--; } } else if((iUserMonth-1)==4||(iUserMonth-1)==6||(iUserMonth-1)==9||(iUserMonth-1)==11&&iInputDays>=30) { iInputDays-=30; iUserMonth--; } if(iUserMonth<1) { iUserMonth=12; iUserYear--; } } iUserDay-=iInputDays; if(iUserDay < 1) { if((iUserMonth-1)==1||(iUserMonth-1)==3||(iUserMonth-1)==5||(iUserMonth-1)==7||(iUserMonth-1)==8||(iUserMonth-1)==10||(iUserMonth-1)==0) { iUserDay=31 iUserDay; iUserMonth--; } else if((iUserMonth-1)==2) { if(iUserYear%4==0&&(iUserYear0!=0||iUserYear@0==0)) { iUserDay=29 iUserDay; iUserMonth--; } else { iUserDay=28 iUserDay; iUserMonth--; } } else { iUserDay=30 iUserDay; iUserMonth--; } } if(iUserMonth==0) { iUserMonth=12; iUserYear--; } FormUI->DateTimePicker3->DateTime = StrToDateTime(Format("%d/%d/%d", ARRAYOFCONST((iUserYear, iUserMonth, iUserDay)))); |
e_snare
一般會員 發表:26 回覆:35 積分:12 註冊:2004-03-14 發送簡訊給我 |
|
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
e_snare
一般會員 發表:26 回覆:35 積分:12 註冊:2004-03-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |