|
|||||||||||
| 技術交流 | 電路欣賞 | 工控天地 | 數字廣電 | 通信技術 | 電源技術 | 測控之家 | EMC技術 | ARM技術 | EDA技術 | PCB技術 | 嵌入式系統(tǒng) 驅動編程 | 集成電路 | 器件替換 | 模擬技術 | 新手園地 | 單 片 機 | DSP技術 | MCU技術 | IC 設計 | IC 產業(yè) | CAN-bus/DeviceNe |
公歷萬年歷星期怎么根據年份和月份計算 |
| 作者:eitan 欄目:單片機 |
各位高手: 大家好! 請問公歷萬年歷的星期怎樣根據年份和月份計算。輸入年份和月份就可以計算出來星期幾? |
| 2樓: | >>參與討論 |
| 作者: 汽車電子 于 2006/12/5 16:34:00 發(fā)布:
我網站有 超級簡單的RTC軟件萬年歷程序 |
|
| 3樓: | >>參與討論 |
| 作者: dengm 于 2006/12/5 20:17:00 發(fā)布:
re http://bbs.21ic.com/club/bbs/showEssence.asp?id=5072 |
|
| 4樓: | >>參與討論 |
| 作者: eitan 于 2007/1/16 17:09:00 發(fā)布:
萬年歷中公歷日期怎樣轉換成農歷日期 各位高手: 大家好!先謝謝上面兩位高位,上次問題“公歷萬年歷星期怎么根據年份和月份計算”已經弄明白。 現在我想問一下:萬年歷中的公歷日期是怎樣轉換成農歷日期的,也就是怎樣根據公歷日期計算出農歷日期。最好說明一下原理。只有程度代碼比較難看懂。謝謝。 |
|
| 5樓: | >>參與討論 |
| 作者: dengm 于 2007/1/16 18:32:00 發(fā)布:
有空寫一個用歷法算發(fā)的最小的,。。。請等待。 |
|
| 6樓: | >>參與討論 |
| 作者: stycx 于 2007/1/16 19:25:00 發(fā)布:
好象都是查表法 |
|
| 7樓: | >>參與討論 |
| 作者: pheavecn 于 2007/1/17 11:42:00 發(fā)布:
我也貼段程序,跟汽車的電子的是一樣的作用。 //以下是包含部分 typedef unsigned CHAR uint8; /* defined for unsigned 8-bits integer variable 無符號8位整型變量 */ typedef signed CHAR int8; /* defined for signed 8-bits integer variable 有符號8位整型變量 */ typedef unsigned SHORT uint16; /* defined for unsigned 16-bits integer variable 無符號16位整型變量 */ typedef signed SHORT int16; /* defined for signed 16-bits integer variable 有符號16位整型變量 */ typedef unsigned int uint32; /* defined for unsigned 32-bits integer variable 無符號32位整型變量 */ typedef signed int int32; /* defined for signed 32-bits integer variable 有符號32位整型變量 */ typedef struct{ uint16 year; uint16 dayOfyear; unsigned CHAR month; unsigned CHAR dayOfmonth; unsigned CHAR hour; unsigned CHAR minute; unsigned CHAR second; unsigned CHAR dayOfweek; unsigned CHAR changed; }TLPC_RTC; void DaysToRtc(uint32 days,TLPC_RTC *rtc); void SecondsToRtc(uint32 seconds,TLPC_RTC *rtc); uint32 RtcToDays(TLPC_RTC rtc); uint32 RtcToSeconds(TLPC_RTC rtc); uint8 DaysOfmonth(uint8 month,uint32 year); //以下是代碼 //--年被4整除、 uint8 DaysOfmonth(uint8 month,uint32 year) { SWITCH(month) { case 1:return 31; break; case 2: if((year%4)==0) { return 29; } else { return 28; } break; case 3:return 31; break; case 4:return 30; break; case 5:return 31; break; case 6:return 30; break; case 7:return 31; break; case 8:return 31; break; case 9:return 30; break; case 10:return 31; break; case 11:return 30; break; case 12:return 31; break; default: return 30; break; } } uint32 RtcToDays(TLPC_RTC rtc) { uint32 ui32; uint32 year; uint8 ui8; year=rtc.year-2000; ui32=(year/4)*(3*365+366); year=year%4; ui32+=year*365; if(year>0)ui32++; for(ui8=1;ui8<rtc.month;ui8++) { ui32+=DaysOfmonth(ui8,year); } ui32+=(rtc.dayOfmonth-1); return ui32; } //-- uint32 RtcToSeconds(TLPC_RTC rtc) { uint32 ui32; ui32=RtcToDays(rtc); ui32=ui32*24*3600; ui32+=rtc.hour*3600l; ui32+=rtc.minute*60l; ui32+=rtc.second; return ui32; } //==================================== void DaysToRtc(uint32 days,TLPC_RTC *rtc) { uint32 ui32,year; uint8 ui8,ui8a; ui32=days/(3*365+366)*4; days=days-ui32/4*(3*365+366); year=0; if(days>=366) { days-=366;year++; year+=days/365; days=days%365; } ui32+=year; (*rtc).year=ui32+2000; for(ui8=1;ui8<12;ui8++) { ui8a=DaysOfmonth(ui8,year); if(days>=ui8a) { days-=ui8a; } else { break; } } (*rtc).month=ui8; (*rtc).dayOfmonth=days+1; return; } //==================================== void SecondsToRtc(uint32 seconds,TLPC_RTC *rtc) { uint32 ui32; ui32=seconds/(24*3600); seconds=seconds%(24*3600); DaysToRtc(ui32,rtc); ui32=seconds/3600; seconds%=3600; (*rtc).hour=ui32; ui32=seconds/60; seconds%=60; (*rtc).minute=ui32; (*rtc).second=seconds; return; } //以下是BCB中測試代碼 |
|
| 8樓: | >>參與討論 |
| 作者: pheavecn 于 2007/1/17 11:48:00 發(fā)布:
測試代碼: void __fastcall TBusStationForm::Button15Click(TObject *Sender) { uint32 days,days1; TLPC_RTC rtc,rtc1; strlist->Clear(); AnsiString stemp,stemp1; AnsiString stra,strb; for(days=0;days<25*(3*365+366);days++) { DaysToRtc(days,&rtc); days1=RtcToDays(rtc); DaysToRtc(days1,&rtc1); if(rtc.dayOfmonth==1) { strlist->Items->Add(""); if(rtc.month==1) { strlist->Items->Add(""); } } stemp=""; stemp1=IntToStr(days);while(stemp1.Length()<4){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="==>"; stemp+=IntToStr(rtc.year);stemp+="年"; stemp1=IntToStr(rtc.month);while(stemp1.Length()<2){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="月"; stemp1=IntToStr(rtc.dayOfmonth);while(stemp1.Length()<2){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="日"; stra=stemp; stemp=""; stemp1=IntToStr(days1);while(stemp1.Length()<4){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="==>"; stemp+=IntToStr(rtc1.year);stemp+="年"; stemp1=IntToStr(rtc1.month);while(stemp1.Length()<2){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="月"; stemp1=IntToStr(rtc1.dayOfmonth);while(stemp1.Length()<2){stemp1=" "+stemp1;}; stemp+=stemp1;stemp+="日"; strb=stemp; stemp=stra+"==>"+strb; if(stra!=strb){stemp=stemp+"*****";}; strlist->Items->Add(stemp); } strlist->Items->SaveToFile("c:\\a.txt"); } //--------------------------------------------------------------------------- |
|
| 9樓: | >>參與討論 |
| 作者: eitan 于 2007/1/19 15:39:00 發(fā)布:
reply pheavecn 您好,你那段c語言看不太明白,麻煩你大概說明一下原理,看起程序來大概有個思路,好明白點,謝謝! * - 本貼最后修改時間:2007-1-19 15:49:19 修改者:eitan |
|
| 10樓: | >>參與討論 |
| 作者: eitan 于 2007/1/19 15:43:00 發(fā)布:
reply 還有那位高手用匯編寫過農歷萬年歷的,請指教,謝謝! |
|
|
|
| 免費注冊為維庫電子開發(fā)網會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號 |