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1, 0, 1&nbs=
p;},=20
=
<BR>{ 40, 0, 0, 59, 0, 1, 0, 0,&n=
bsp;1, 0, 1, 1, 0, 1, 1, 0, 1&nbs=
p;}, /* 2024 */=20
=
<BR>{ 28, 6, 2, 5, 1, 0, 1, 0,&nb=
sp;0, 1, 0, 1, 0, 1, 1, 1, 0 =
;},=20
=
<BR>{ 47, 0, 3, 10, 1, 0, 1, 0,&n=
bsp;0, 1, 0, 0, 1, 1, 1, 0, 1&nbs=
p;},=20
=
<BR>{ 36, 0, 4, 15, 1, 1, 0, 1,&n=
bsp;0, 0, 1, 0, 0, 1, 1, 0, 1&nbs=
p;},=20
=
<BR>{ 25, 5, 5, 20, 1, 1, 1, 0,&n=
bsp;1, 0, 0, 1, 0, 0, 1, 1, 0&nbs=
p;}, /* 2028 */=20
=
<BR>{ 43, 0, 0, 26, 1, 1, 0, 1,&n=
bsp;0, 1, 0, 1, 0, 0, 1, 0, 1&nbs=
p;},=20
=
<BR>{ 32, 0, 1, 31, 1, 1, 0, 1,&n=
bsp;1, 0, 1, 0, 1, 0, 1, 0, 0&nbs=
p;},=20
=
<BR>{ 22, 3, 2, 36, 0, 1, 1, 0,&n=
bsp;1, 0, 1, 1, 0, 1, 0, 1, 0&nbs=
p;} };=20
=
<BR><BR>#define lastyear (firstyear+sizeof(lunarcal)/sizeof(str=
uct taglunarcal)-1)=20
=
<BR><BR>/* =CE=F7=C0=FA=C4=EA=C3=BF=D4=C2=D6=AE=C8=D5=CA=FD */ =
=
<BR>int solarcal[12] =3D { 31, 28, 31, =
;30, 31, 30, 31, 31, 30, 31, 30, =
31 };=20
=
<BR><BR>/* =CE=F7=C0=FA=C4=EA=C3=BF=D4=C2=D6=AE=C0=DB=BB=FD=C8=D5=CA=
=FD, =C6=BD=C4=EA=D3=EB=C8=F2=C4=EA */=20
<BR>int solardays[2][14] =3D {=20
=
<BR>{ 0, 31, 59, 90, 120, 151, 181,&nb=
sp;212, 243, 273, 304, 334, 365, 396 }=
,=20
=
<BR>{ 0, 31, 60, 91, 121, 152, 182,&nb=
sp;213, 244, 274, 305, 335, 366, 397 }=
};=20
=
<BR><BR>/* =C7=F3=B4=CB=CE=F7=C0=FA=C4=EA=CA=C7=B7=F1=CE=AA=C8=F2=C4=
=EA, =B7=B5=BB=D8 0 =CE=AA=C6=BD=C4=EA, 1 =CE=AA=
=C8=F2=C4=EA */=20
<BR>int getleap( int year ) <BR>{=20
=
<BR> if ( year % 400 =3D=3D=
0 )=20
=
<BR> return 1;=20
=
<BR> else if ( year % 100=
=3D=3D 0 )=20
=
<BR> return 0;=20
=
<BR> else if ( year % 4&n=
bsp;=3D=3D 0 )=20
=
<BR> return 1;=20
<BR> else=20
=
<BR> return 0;=20
<BR>} =
<BR><BR>/* =CE=F7=C0=FA=C5=A9=C0=FA=D7=AA=BB=BB */=20
=
<BR>int calconv( struct convdate *cd )=20
<BR>{=20
=
<BR> int leap, d, sm, y, =
im, l1, l2, acc, i, lm, kc;=20
=
<BR> if ( cd->source =3D=3D =
;0 ) /* solar */=20
<BR> {=20
=
<BR> if ( cd->=
;solaryear <=3D firstyear || cd->solaryear =
;> lastyear )=20
=
<BR> &nb=
sp;return 1;=20
=
<BR> sm =3D cd-&=
gt;solarmonth - 1;=20
=
<BR> if ( sm&nbs=
p;< 0 || sm > 11 )=20
=
<BR> &nb=
sp;return 2;=20
=
<BR> leap =3D ge=
tleap( cd->solaryear );=20
=
<BR> if ( sm&nbs=
p;=3D=3D 1 )=20
=
<BR> &nb=
sp;d =3D leap + 28;=20
<BR> else=20
=
<BR> &nb=
sp;d =3D solarcal[sm];=20
=
<BR> if ( cd->=
;solardate < 1 || cd->solardate > =
d )=20
=
<BR> &nb=
sp;return 3;=20
=
<BR> y =3D cd-&g=
t;solaryear - firstyear;=20
=
<BR> acc =3D sol=
ardays[leap][sm] + cd->solardate;=20
=
<BR> cd->weekday =3D=
( acc + lunarcal[y].baseweekday ) % 7=
;=20
=
<BR> kc =3D acc&=
nbsp;+ lunarcal[y].basekanchih;=20
=
<BR> cd->kan =3D&n=
bsp;kc % 10;=20
=
<BR> cd->chih =3D&=
nbsp;kc % 12;=20
=
<BR> if ( acc&nb=
sp;<=3D lunarcal[y].basedays )=20
<BR> {=20
=
<BR> &nb=
sp;y--;=20
=
<BR> &nb=
sp;cd->lunaryear =3D cd->solaryear - 1;=20
=
<BR> &nb=
sp;leap =3D getleap( cd->lunaryear );=20
=
<BR> &nb=
sp;sm +=3D 12;=20
=
<BR> &nb=
sp;acc =3D solardays[leap][sm] + cd->solardate;=20
<BR> }=20
<BR> else=20
=
<BR> cd->lunaryear =
;=3D cd->solaryear;=20
=
<BR> l1 =3D lunarcal[y].basedays;=20
=
<BR> for ( i=3D0; i<13; i++=
)=20
<BR> {=20
=
<BR> l2 =3D l1&n=
bsp;+ lunarcal[y].monthdays[i] + 29;=20
=
<BR> if ( acc&nb=
sp;<=3D l2 )=20
=
<BR> &nb=
sp;break;=20
=
<BR> l1 =3D l2; =
<BR> }=20
=
<BR> cd->lunarmonth =3D i + =
;1;=20
=
<BR> cd->lunardate =3D acc -&nbs=
p;l1;=20
=
<BR> im =3D lunarcal[y].intercalation;=20
=
<BR> if ( im !=3D 0 &=
& cd->lunarmonth > im )=20
<BR> {=20
=
<BR> cd->lunarmonth--; =
=
<BR> if ( cd->=
;lunarmonth =3D=3D im )=20
=
<BR> &nb=
sp;cd->lunarmonth =3D -im;=20
<BR> }=20
=
<BR> if ( cd->lunarmonth >&nb=
sp;12 )=20
=
<BR> cd->lunarmonth&nbs=
p;-=3D 12;=20
<BR> }=20
<BR> else /* lunar */=20
<BR> {=20
=
<BR> if ( cd->=
;lunaryear < firstyear || cd->lunaryear &g=
t;=3D lastyear )=20
=
<BR> &nb=
sp;return 1;=20
=
<BR> y =3D cd-&g=
t;lunaryear - firstyear;=20
=
<BR> im =3D luna=
rcal[y].intercalation;=20
=
<BR> lm =3D cd-&=
gt;lunarmonth;=20
=
<BR> if ( lm&nbs=
p;< 0 )=20
<BR> {=20
=
<BR> &nb=
sp;if ( lm !=3D -im )=20
=
<BR> &nb=
sp; return 2;=20
<BR> }=20
=
<BR> else if (&n=
bsp;lm < 1 || lm > 12 )=20
=
<BR> &nb=
sp;return 2;=20
=
<BR> if ( im&nbs=
p;!=3D 0 )=20
<BR> {=20
=
<BR> &nb=
sp;if ( lm > im )=20
=
<BR> &nb=
sp; lm++;=20
=
<BR> &nb=
sp;else if ( lm =3D=3D -im )=20
=
<BR> &nb=
sp; lm =3D im + 1;=20
<BR> }=20
<BR> lm--;=20
=
<BR> if ( cd->=
;lunardate > lunarcal[y].monthdays[lm] + 29 )=
=20
=
<BR> &nb=
sp;return 3;=20
=
<BR> acc =3D lun=
arcal[y].basedays;=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -