赞
踩
简单的台历式月历设计制作,有农历对照查询功能。
万年历的设计和编制一直是学程序设计很好的课题,其中的难点是农历对照的打印输出格式化显示。历法的天文计算太复杂,小时间跨度的程序用数据方法较为简单。有两种数据方法较好,一是16进制数据,另一是10进制数据,十进制较为直观。都是网上流行的,不知是谁创制的。
本文农历算法采用数据数组方法,1900-2100年日历数据量不大。程序启动时读入即可。
数据结构18位,如daList[2000]="110010010110000205"; 前12位表示正月到腊月大小月,1为农历大月30天,0为小月29天。 第13,14位表示农历闰月,13位为农历闰月大小,14位为闰几月,
后4位表示农历年首个朔日,即俗称的正月初一的公历日期,2月5日。
节气交节时刻计算,天文算法很精准,但太复杂,数据数组方法数据量太大,都不合适。如要求精确时间,可用数据数组方法。本程序采用曾次亮先生的算法,算法简单,但精度差些。
如要精准度就采用数据数组方法,200年的数据量还可以,现在存储和内存容量都较大。我早先编制一程序用于采集农历数据和节气时间数据,数据底本是依据许剑伟先生的寿星万年历的输出打印表。编制的农历数据有公元前1600年到公元3000年和节气时间数据公元1600年至3000年。公元1600年以前的节气时间数据和历史上历朝历代发布的时间差距较大。我编制的程序软件主要适用于历史研究和考古研究故1600年前的节气时刻要参照古历法所记载这些数据。数据文件有需要的可索取。
zbiao( 联系方法:micelu@126.com )
台历式显示月历就是公历和农历格式化打印,7天一星期表式打印输出。农历显示包括初一改为那个月,是节气日期改为节气名称,法定节假日显示。节假日既然是国家法定的,那就应从1949年开始显示。其实各节日哪时开始要考证,故且从权统一从1949年开始。此前也就只显示传统节日。
本文的重点是介绍月历格式化打印方法,此法暂称为十字坐标定位打印法,就是先定一个十字坐标点,即left和top,俗称左上角。接下来所有打印显示的内容都按此点来计算。此方法的优点是很容易在屏幕上改变打印位置,这是排版的要点,若要所见即所得排版A4或A3纸张上打印输出,就很容易实现。用图片框作载体,装载底图,调整底图位置,再定点打印月历,就能打印出很酷的月历。
此法还可以制作pc视窗的桌面透明万年历。用无框窗体加透明图片贴图加月历打印输出就能实现透明万年历的制作。有兴趣的可试试,很酷的。我用VB6就做过。可参阅我本站上传的资源文档。
【 附录 】节气时间数据法示例:
jqdata[2023] = " 05 23:04:38 20 16:29:20 04 10:42:20 19 06:34:05 06 04:36:01 21 05:24:13 05 09:12:51 20 16:13:25" ; //2023年小寒起部份数据
dy=2023 ; dm=2 ;
dm2=intToString (dm) ;
if (dm<10) dm2="0"+dm2 ; //format
ss=jqdata[dy] ; //取年全部数据
s1=subString (ss, dm*24-24, 24) ; //截取月数据
print "ss = "+ss ;
print "截取数据 : "+s1 ;
jqs1=subString (jqnames, (dm*2-1)*2-2, 2);
jqs1=jqs1+" "+dm2+"-"+subString (s1, 1, 12) ;
jqs2=subString (jqnames, dm*2*2-2, 2);
jqs2=jqs2+" "+dm2+"-"+subString (s1, 13, 12) ;
print "-----------------------------------------" ;
print jqs1 ; //打印节气
print jqs2 ; //打印中气
输出打印示例:
截取数据 : 04 10:42:20 19 06:34:05
----------------------------------------------
立春 02-04 10:42:20
雨水 02-19 06:34:05
下面的代码示例文档是用简单的C语言写的,很简洁,适用于初学者。我是在安卓手机上编写的,显示是手机界面。
( 代码中print...是算法测试用,这是我的测试方法,已注释掉 )
以下是示例程序源码:
//******************************************
//* 简明月历 (1900-2100) ver. 1.0.1
//* 最简单的台历式月历设计
//******************************************
Canvas cs; //画布
string sBarDes[10];
int nBarId[10];
float src[4]; //清屏
FileInput filebox;
string fname; //filename 加底图
int ds[3]; //get date yymmdd
int dy,dm,dd;
int wd; //weekday
int alln,alln1;
int ns,leap;
double nleap, nleapd; //农历闰月,0无闰,闰月大小
int i, k, n,n0,n1;
string s,s0,ss,s5, s6 ;
string s1,s2,s3,s4;
string wds,wdss; //weekday星期
float x0,y0,x1,y1; //定位打印
float sx,sy;
string daList[2200]; //农历数据
double dy0,dy1,dm1,dd1;
string dy2,dm2,dd2 ; //日期
double hh1,mm1,ss1;
string hh2,mm2,ss2; //时间
double jn; //计算节气
string jname1,jname2;
string jqnames;
double jd;
double juD,tht,yrD;
double sD; //shouD
double vs,dalt; //计算 solar
string das0,das1,das2; // 0 last yy, 1 this yy, 2 new
double ysm,ysd; //年首月,年首日
int msd[12]; //月朔日
int msd0,msd1;
int mdx ; //农历月大小
int chuxi; //除夕在廿九
string nlms,nlds; //农历月$,农历日$
string getms,getds, mss$ ; //for print nlm$,nld$
string gzs,ggzs; //年干支计算
int gzn;
string sxs,gsxs; //生肖
int sxn;
int jqdn,jqd1,jqd2; //print solar day ( calendar )
string jqs1,jqs2;
string jqss1,jqss2;
int gzy,gzm,gzd,gzh; //干支 yy mm dd hh
int fmn,mn,fn; //母亲节父亲节
int isdraw;
int setc; //节日 color in red
main(){
setTitle ("简明月历 (1900-2100)");
jqnames="小寒大寒立春雨水惊蛰春分清明谷雨立夏小满芒种夏至小暑大暑立秋处暑白露秋分寒露霜降立冬小雪大雪冬至";
nlds="初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十初一初二初三";
wdss="星期日星期一星期二星期三星期四星期五星期六";
nlms="冬月腊月正月二月三月四月五月六月七月八月九月十月冬月腊月";
gzs="甲子乙丑丙寅丁卯戊辰己巳庚午辛未壬申癸酉甲戌乙亥丙子丁丑戊寅己卯庚辰辛己壬午癸未甲申乙酉丙戌丁亥戊子己丑庚寅辛卯壬辰癸巳甲午乙未丙申丁酉戊戌己亥庚子辛丑壬寅癸卯甲辰乙巳丙午丁未戊申己酉庚戌辛亥壬子癸丑甲寅乙卯丙辰丁巳戊午己未庚申辛酉壬戌癸亥";
sxs="鼠牛虎兔龙蛇马羊猴鸡狗猪";
//cs.SetBackground(200,250,200); //底色
setDisplay (1);
cs.Active ();
sBarDes[0]="输入日期";
nBarId[0]=100;
sBarDes[1]="显示月历";
nBarId[1]=101;
sBarDes[2]="< 上一月 ";
nBarId[2]=102;
sBarDes[3]="下一月 > ";
nBarId[3]=103;
sBarDes[4]="退出程序";
nBarId[4]=104;
sBarDes[5]=" ";
nBarId[5]=105;
setToolBarHeight(10);
setButtonTextSize(13);
setToolBarBackgroundColor(255,250,250,250);
setButtonColor(255,240,240,240);
setButtonTextColor(255,0,0,220);
setToolBar(100,myToolBarProc,sBarDes,nBarId,6);
readDat (); //read calendar data 1900-2100
cs.SetBackground (230,230,230) ;
isdraw=0;
fname="/storage/emulated/0/rebtu.jpg";
cs.DrawBitmap(fname,0,2); //加底图,启动页面
cs.SetTextSize (60);
ss="Welcome you ...... ! " ;
cs.SetColor(205,250,150,0);
cs.DrawText (ss, 35, 120);
cs.Update () ;
while (){}
}//main ()
今年是兔年就加个送福兔的启动页面:
//*代码中 print ...... 用于算法检测检验
inputDate (){ //日期输入
string sDat[101];
getDate(ds); //getDate = today
pickDate("输入日期:",ds); //input date
clearOutput ();
//print ds[0],ds[1],ds[2];
dy=ds[0];
dm=ds[1];
dd=ds[2];
print "InputDate = ",dy ,"-",dm,"-",dd;
dd2=intToString(dd); //this day $
getWeekday () ;
}//inputDate()
getWeekday (){//计算星期,月首日星期几
int ty;
int tm;
clearOutput ();
ty=dy;
tm=dm;
if (dm<3){
ty=dy-1;
tm=dm+12;}
//first day=1 this month
//iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)
//mod 7 基姆拉尔森公式
alln=2*tm+3*(tm+1)/5+ty+(int)(ty/4);
alln=alln-(int)(ty/100)+(int)(ty/400)+2;
wd=alln-alln/7*7; //mod (alln,7)
wds=subString(wdss,wd*3,3);
// return weekday = wds
}//getWeekday ()
calnlds(){ //计算农历要素 (print... 调试检测)
//calculate 农历月$ getms 农历日$ getds*******
//double nleap,nleapd; //农历闰月,0无闰,闰月大小
s=daList[dy-1];
das0=s;
print "last year = ",dy-1;
print "last year das0 = ", das0;
s=daList[dy];
das1=s;
print "this year = ",dy;
print "this year das1 = ",das1;
s=subString(das1,15,1);
ysm=stringToDouble(s);
print "年首月 = ",(int)(ysm);
s=subString(das1,16,2);
ysd=stringToDouble(s);
print "月首日 = ",(int)(ysd);
s=subString(das1,13,1);
if (s=="a") s="10" ; //y1984 闰十月
nleap=stringToDouble (s);
n=(int)(nleap);
s=subString(das1,12,1);
nleapd=stringToDouble (s);
k=(int)(nleapd) ;
print "农历闰月 nleap = ", n," 闰月大小 = ", k ;
//截串拼成新串,计算农历月日
if(nleap==0){
ss=subString (das0,10,2)+subString (das1,0,12);
}else {ss=subString(das0,11,1)+subString(das1,0,n)+subString(das1,12,1)+subString(das1,n,12-n) ; }
if (dy==1919) ss="11010010011011" ; //有农历闰月,初一在2月 ,调整
if (dy==1984) ss="11101100100101" ;
if (dy==2052) ss="11010010010111" ;
das2=ss;
print "new das2 = ",das2;
print " ";
//**** calculate msd(12) // 全年 月朔日$
n0=(int)(ysd); //年首日起算
if (dy-(int)(dy/4)*4==0){leap=1;}else{leap=0;}
//print "leap = ",leap;
if (ysm==1){
s=subString(das2,1,1);
if (s=="1"){n=30;}else{n=29;}
msd[1]=n0;
msd[2]=msd[1]+n-31; }
if (ysm==2){
s=subString(das2,1,1);
if (s=="1"){n=30;}else{n=29;}
msd[1]=31+n0-n;
msd[2]=n0; }
s=subString(das2,2,1);
if (s=="1"){n=30;}else{n=29;}
msd[3]=msd[2]+n-28-leap;
s=subString(das2,3,1);
if (s=="1"){n=30;}else{n=29;}
msd[4]=msd[3]+n-31;
s=subString(das2,4,1);
if (s=="1"){n=30;}else{n=29;}
msd[5]=msd[4]+n-30;
s=subString(das2,5,1);
if (s=="1"){n=30;}else{n=29;}
msd[6]=msd[5]+n-31;
s=subString(das2,6,1);
if (s=="1"){n=30;}else{n=29;}
msd[7]=msd[6]+n-30;
s=subString(das2,7,1);
if (s=="1"){n=30;}else{n=29;}
msd[8]=msd[7]+n-31;
s=subString(das2,8,1);
if (s=="1"){n=30;}else{n=29;}
msd[9]=msd[8]+n-31;
s=subString(das2,9,1);
if (s=="1"){n=30;}else{n=29;}
msd[10]=msd[9]+n-30;
s=subString(das2,10,1);
if (s=="1"){n=30;}else{n=29;}
msd[11]=msd[10]+n-31;
s=subString(das2,11,1);
if (s=="1"){n=30;}else{n=29;}
msd[12]=msd[11]+n-30;
print "全年朔日 : ";
for(i=1;i<13;i++){
print "dm= ",i," ",msd[i];}
getds=" ";
n0=msd[dm]; //msd 月朔日
s=subString(das2,dm-1,1);
if (n0<=1) s=subString (das2,dm,1);
if(s=="1"){n=30;}else{n=29;}
if(n0<=1)n0=n+n0;
if(n0>30)n0=n0-30 ;
msd1=n0;
print "月朔日msd1: ", msd1 ;
string gs1,gs2;
gs1=subString(nlds,(n-n0+1)*2,(n0-1)*2);
gs2=subString(nlds,0,(31-n0+1)*2);
getds=gs1+gs2;
print "getds = "+getds; //农历日$
//农历月名$ ******** 1919 1984 2052 ysd=2-1
//mdx 月大小,大30d,小29d
//mss$ 用于显示 是日在此月初一前的农历月份
n1=(int)(nleap); //2017 nleap n1=6;
if(ysm==2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ;
if (msd1>22){ // 22-02-01 正月初一
getms=subString(nlms,dm*2+2,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm+1 ; }
} //正月为 2 月份
if(ysm==1){ //正月为 1 月份
if(dm<n1+1){
getms=subString(nlms,dm*2+2,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm ; }
if(dm==n1+1){
getms="闰"+subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2,2);
mdx=dm+1 ; }
if(dm>n1+1){
getms=subString(nlms,dm*2,2);
mss$="闰"+subString(nlms,dm*2-2,2);
mdx=dm ; }
if(dm>n1+2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ; }
}
//y1984 闰10小, y1919 r17 闰7大, y2052闰8小
if(dy==1919||dy==1984||dy==2052){
if(dm<n1+1){ //闰年正月为 2 月份,偏差调整
k=0 ; if (dm>4) k=2 ;
getms=subString(nlms,dm*2+k,2);
mss$=subString(nlms,dm*2, 2);
mdx=dm ;
if (k==2) mdx=dm+1 ; }
if(dm==n1+1){
getms="闰"+subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2,2);
mdx=dm+1 ; }
if(dm>n1+1){
getms=subString(nlms,dm*2,2);
mss$="闰"+subString(nlms,dm*2-2,2);
mdx=dm ; }
if(dm>n1+2){
getms=subString(nlms,dm*2,2);
mss$=subString(nlms,dm*2-2, 2);
mdx=dm ; }
}
if(dy==2052&&dm==4) {
getms=subString(nlms,dm*2+2,2);
mdx=dm+1 ; }
s1=getms ; //print " 月"
if(s1=="冬月")s1="十一月";
if(s1=="腊月")s1="十二月";
getms=s1 ;
s1=mss$; //print " 月"
if(s1=="冬月")s1="十一月";
if(s1=="腊月")s1="十二月";
mss$=s1 ; //替换
s3=subString(das2,mdx ,1);
if (dy==1984){ s3=subString (das2, dm+1, 1) ; }
if(s3=="1"){s3="大"; chuxi=0; }
else{s3="小"; chuxi=1; }
print "本月 getms = ", getms+s3;
print "上月 mss$ = ", mss$ ;
print "月份 = ",dm, " >>> 农历月 = ",getms+s3;
}//calnlds ()
calendar(){ //格式化打印输出
//calculate and show calendar ************
calnlds(); //取得农历日$ getms, getds
cs.ClearDraw (0,src); //clear screen
string fname;
fname="/storage/emulated/0/view022.jpg";
cs.DrawBitmap(fname,0,2); //加底图
isdraw=0;
// print " show weekday = ",wd; //test
//此定位方法可调整打印输出位置
sx=280 ; sy=280 ; //set left top 定位
cs.SetTextStyle (1); //粗体
cs.SetStrokeWidth (1);
s=intToString (dm); //print big dm
if (dm<10){x1=sx-10;}else{x1=sx-100;}
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextSize (300); //print big dm
cs.SetColor (80,0,160,0);
cs.DrawText (s, x1,sy+290);
cs.SetFillMode (0);//0不填色,1填色
cs.SetTextSize (300); //print big dm
cs.SetColor (200,250,100,0);
cs.DrawText (s, x1, sy+290);
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextSize (19);
cs.SetColor (255,255,0,0);
s="星期日";
cs.DrawText (s,sx-167,sy-70);
s="星期六";
cs.DrawText (s,sx+252 ,sy-70);
cs.SetColor(255,0,0,240);
s="星期一 星期二 星期三 星期四 星期五”;
cs.DrawText (s,sx-94, sy-70);
cs.DrawLine(sx-190,sy-100,sx+340,sy-100);
cs.DrawLine(sx-190,sy-50,sx+340,sy-50);
cs.DrawLine(10,sy+450,690,sy+450);
cs.SetTextSize (66); //print yymm
s=intToString (dy)+" · ";
leap=0;
n=0;
if (dm<10)n=20;
s1=intToString (dm);
cs.SetColor(220,0,90,0);
cs.DrawText (s+s1,sx+50+n+4,sy-120+3);
cs.SetColor(255,0,0,240);
cs.DrawText (s+s1,sx+50+n,sy-120);
cs.SetFillMode (0);//0不填色,1填色
cs.SetColor(255,250,160,0);
cs.DrawText (s+s1,sx+50+n,sy-120); //print yymm
cs.SetColor(255,0,0,240);
cs.SetFillMode (1);//0不填色,1填色
//**** calculate solarterm //show 节气
dy2=intToString(dy); //show 节气
dm2=intToString(dm);
dy1=stringToDouble(dy2);
dm1=stringToDouble(dm2);
cs.SetTextSize (30);
dy0=dy1;
n=dm*2-1;
caljq(); //节气计算
jqd1=(int)(dd1);
jqs1=subString(jname2,0,2);
cs.DrawText (jname2,sx-160,sy+490);
jqss1=jname2;
n=dm*2;
caljq (); //节气计算
jqd2=(int)(dd1);
jqs2=subString(jname2,0,2);
cs.DrawText(jname2,sx-160,sy+530);
jqss2=jname2;
//***** print 干支年 生肖
if(ysm==2&&dm==1){n=dy-4-1;}else{n=dy-4;}
gzn=(n-n/60*60);
ggzs=subString(gzs,gzn*2,2);
s1=getms+s3;
s=ggzs+"年"+s1 ; //年干支
sxn=gzn-gzn/12*12; //生肖
gsxs=subString(sxs,sxn,1);
ggzs=s+"("+gsxs+")";
cs.SetTextSize (26); //干支年月生肖
cs.DrawText(ggzs,sx-170, sy-120);
string nss ; //计算是月天数
double dns ;
nss="00312831303130313130313031" ;
s=subString (nss, dm*2, 2 ) ;
dns=stringToDouble (s) ;
ns=(int)(dns) ;
if (dy/4*4==dy)leap=1;
if (dm==2&&leap==1)ns=29 ;
//台历式月历定位打印输出较为复杂,
//下面介绍一种算法,
//输出为 6行 7列,x0 =7列, y0 =6行,
//x1, y1 调整打印坐标
cs.SetColor (255,0,0,240);
fmn=0; k=dd ; //打印月历
for (i=1; i<=ns ; i++){//print AD. get mm dd $
cs.SetColor (255,0,0,240);
cs.SetTextSize (30);
n=0; setc=0;
x0=(i+wd-1)-((i+wd-1)/7*7); //mod (sx,7)
y0=(i+wd-1)/7;
if (x0==0||x0==6)cs.SetColor(255,255,0,0);
//以下设置节日显示
if (i==1&&dy>1948){ //红色,国定假开国起
if (dm==1||dm==5||dm==6||dm==7||dm==8||dm==10){cs.SetColor(255,255,0,0); } }
if(dm==ysm&&i==ysd-1)cs.SetColor (255,255,0,0);
if(dm==ysm&&i==ysd)cs.SetColor (255,255,0,0);
if (x0==0)fmn=fmn+1; //父亲节母亲节第几周
if (dm==5&&fmn==2&&x0==0)mn=i;
if (dm==6&&fmn==3&&x0==0)fn=i;
//for father mather festival
x1=x0*70+114+sx-200 ; //调整打印坐标left
y1=y0*80+300+sy-300 ; // top
s=intToString(i);
n=0;
if (len(s)==1)n=10;
cs.DrawText (s,x1+n-70, y1); //print AD.date$
cs.SetTextSize (20);
// **** s="初一"; //打印农历日期 *******
n=0;
s=subString (getds,(i-1)*2,2); //print dd$
s2=s; //show festival
if(s=="初一"){
s=getms; //print " m月"
if (ysm==2&&msd1==1&& i>29){
//****y1984-5 y2024-12
s=subString (nlms,dm*2+2,2); }
if(s=="冬月")s="十一月";
if(s=="腊月")s="十二月"; }
//**** show festival ***************
//**** output solarterm on table
if(i==jqd1)s=jqs1; //打印节气
if(i==jqd2)s=jqs2;
if(dm==1&&i==1) s="元旦节";
if(dm==ysm&&i==ysd-1)s="除夕";
if(dm==ysm&&i==ysd)s="春节";
if (dy>1948){ //国定假
if(dm==2&&i==14)s="情人节";
if(dm==3&&i==8)s="妇女节";
if(dm==3&&i==12)s="植树节";
if(dm==5&&i==1)s="劳动节";
if(dm==5&&i==4)s="青年节";
if(dm==5&&i==mn)s="母亲节";
if(dm==6&&i==fn)s="父亲节";
if(dm==6&&i==1)s="儿童节";
if(dm==7&&i==1)s="建党节";
if(dm==8&&i==1)s="建军节";
if(dm==9&&i==10)s="教师节";
if(dm==10&&i==1) s="国庆节";
} //国定假
if(dm==12&&i==25) s="圣诞节";
if(getms=="二月"&&s2=="十五"&& i<msd1){s="元宵节";setc=12;}
if(getms=="正月"&&s2=="十五"&& i>msd1){s="元宵节";setc=12;}
if(getms=="三月"&&s2=="初二"&& i<msd1)s="龙抬头";
if(getms=="二月"&&s2=="初二"&& i>msd1)s="龙抬头";
if(getms=="六月"&&s2=="初五"&& i<msd1){s="端'午节"; setc=12;}
if(getms=="五月"&&s2=="初五"&& i>msd1){s="端午节"; setc=12;}
if(getms=="八月"&&s2=="初七"&&i<msd1)s="七夕节";
if(getms=="七月"&&s2=="初七"&&i>msd1)s="七夕节";
if(getms=="八月"&&s2=="十五"&&i<msd1)s="中元节";
if(getms=="七月"&&s2=="十五"&&i>msd1)s="中元节";
if(getms=="九月"&&s2=="十五"&&i<msd1){s="中秋节"; setc=12; s6=s ; }
s6="" ;
if(getms=="八月"&&s2=="十五"&& i>msd1){s="中秋节"; setc=12; s6=s ; }
if(dm==10&&i==1){ s="国庆节"; }
if(getms=="十月"&&s2=="初九"&& i<msd1){s="重阳节"; setc=12;}
if(getms=="九月"&&s2=="初九"&& i>msd1){s="重阳节";setc=12;}
if(getms=="正月"&&s2=="初八"&&i<msd1)s="腊八节";
if(getms=="十二月"&&s2=="初八"&&i>msd1)s="腊八节";
if(getms=="正月"&&s2=="廿三"&& i<msd1)s="小年";
if(getms=="十二月"&&s2=="廿三"&& i>msd1)s="小年";
if (i==(msd1-1)&&chuxi==1&&s1=="十二月"&&s2=="廿九"&&dm<2)s="除夕";
if (setc==12)cs.SetColor (255,255,0,0);
if (len(s)==3)n=10;
cs.DrawText(s,x1-2-n-70, y1+30); //print ch
if(dd==i){ //draw today mark ****
cs.SetFillMode (0) ;
cs.SetColor (255,250,0,0);
cs.DrawRect (x1-80,y1-30,x1-25,y1+10);
cs.SetFillMode (1) ;
cs.SetColor (100,250,250,20);
cs.DrawRect (x1-80,y1-30,x1-25,y1+10); }
} //print AD. dd$ & festival
setDisplay (1);
cs.Update ();
}//calendar () ***********************
myToolBarProc(int nBtn,int nContext) { //菜单按钮
if(nBtn==100){//计算星期, 显示月历
inputDate () ;
calendar(); }
if(nBtn==101){//显示月历
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
getWeekday ();
calendar () ; }
if(nBtn==102){//上一月
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
dm=dm-1 ;
if (dm<1) { dy=dy-1 ; dm=12 ; }
if (dm==2&&dd>28){ dd=28 ; }
if (dd>30){ dd=30 ; }
getWeekday ();
calendar () ;
}
if(nBtn==103){//下一月
if (dy<1900) {
getDate(ds); //getDate = today
dy=ds[0] ;
dm=ds[1] ;
dd=ds[2] ; }
dm=dm+1 ;
if (dm>12) { dy=dy+1 ; dm=1; }
if (dm==2&&dd>28){ dd=28 ; }
if (dd>30){ dd=30 ; }
getWeekday ();
calendar () ;
}
if(nBtn==104){//退出程序
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
if(nBtn==105){//空
setDisplay (0);
}
}//Toolbar () ***********************
caljq(){//calculate solar ** return jname2
juD=dy0*(365.2423112-0.000000000000064
*(dy0-100)*(dy0-100)- 0.00000003047
*(dy0-100))+15.218427*n+1721050.71301;
tht=0.0003*dy0-0.372781384-0.2617913325*n;
yrD=(1.945*sin(tht)-0.01206*sin(2*tht))
*(1.048994-0.00002583 *dy0);
sD=-0.0018*sin(2.313908653*dy0
-0.439822951-3.0443*n);
//'vs = juD '** 平气
vs = (juD + yrD + sD); // '** 定气
dalt=-15+(juD-2382148)*(juD-2382148)/41048480;
//print dalt;
dalt = dalt/86400;
//print dalt;
jd = vs - 0.5 - dalt-0.025;
jdtoGD (); //reture jname2;
}//caljq() ***********************************
//calculate jd to GD ** return jname2 *****
jdtoGD(){
double a,b,c,d,e;
double F;
double allss;
F=jd-(int)(jd);
//print " ";
//print " JD = ",jd;
//print " 时分秒 日小数 = ",F;
a=(int)(jd+0.5);
b=a+1537;
c=(int)((b-122.1)/365.25);
d=(int)(365.25*c);
e=(int)((b-d)/30.6001);
dd1=b-d-(int)(30.6001*e);
dm1=e-1-(int)((e/14)*12);
dy1=c-4715-(int)((7+dm1)/10);
//print a," ",b," ",c," ",d," ",e;
dy2=intToString (dy);
dm2=intToString (dm);
dd2=doubleToString (dd1);
if (len(dm2)==1)dm2="0"+dm2;
if (dd1<10)dd2="0"+dd2;
dd2=subString (dd2,0,2);
//print dy2+" 年 "+dm2+" 月 "+dd2+" 日 ";
if(n==24)jqdn=(int)(dd1);
if (n==24&&dm1<3)jqdn=jqdn+1;
//**** 日allss 的小数转为时分秒
allss=(int)((jd-a)*86400+43200.5);
//print "allss = ", allss;
hh1=(int)(allss/3600);
mm1=(int)((allss-hh1*3600)/60);
ss1=(int)(allss-hh1*3600-mm1*60);
if(ss1>=60){
ss1=ss1-60;
mm1=mm1+1;}
if(mm1>=60){
mm1=mm1-60;
hh1=hh1+1;}
//**** print "JD 转为 GD,计算结果:”;
hh2=doubleToString(hh1);
mm2=doubleToString(mm1);
ss2=doubleToString(ss1);
if(hh1<10){
hh2="0"+doubleToString(hh1);}
if(mm1<10){
mm2="0"+doubleToString(mm1);}
if(ss1<10){
ss2="0"+doubleToString(ss1);}
hh2=subString (hh2,0,2);
mm2=subString (mm2,0,2);
ss2=subString (ss2,0,2);
jname1=subString(jqnames,(n-1)*2,2);
//print "节气 : ",jname1;
jname2=jname1+" > "+dm2+"-"+dd2+" "+hh2+":"+mm2+":"+ss2;
//return jname2;
}//jdtoGD() **************
readDat(){
daList[1899] = "101010110101000210";
daList[1900] = "010010111101080131";
daList[1901] = "010010101110000219";
daList[1902] = "101001010111000208";
daList[1903] = "010100100110050129";
daList[1904]= "110100100110000216";
daList[1905] = "110110010101000204";
daList[1906]= "011010101010140125";
daList[1907] = "010101101010000213";
daList[1908] = "100110101101000202";
daList[1909]= "010010101110020122";
daList[1910]= "010010101110000210";
daList[1911] = "101001001101060130";
daList[1912]= "101001001101000218";
daList[1913]= "110100100101000206";
daList[1914] = "110101010100150126";
daList[1915]= "101101010101000214";
daList[1916]= "010101101010000204";
daList[1917]= "100101101101020123";
daList[1918]= "100101011011000211";
daList[1919]= "010010011011170201";
daList[1920]= "010010011011000220";
daList[1921]= "101001001011000208";
daList[1922]= "101100100101050128";
daList[1923]= "011010100101000216";
daList[1924] = "011011010100000205";
daList[1925] = "101011011010140124";
daList[1926] = "001010110110000213";
daList[1927] = "100101010111000202";
daList[1928]= "010010010111020123";
daList[1929]= "010010010111000210";
daList[1930] = "011001001011060130";
daList[1931] = "110101001010000217";
daList[1932] = "111010100101000206";
daList[1933] = "011011010100150126";
daList[1934] = "010110101101000214";
daList[1935] = "001010110110000204";
daList[1936]= "100100110111130124";
daList[1937] = "100100101110000211";
daList[1938]= "110010010110170131";
daList[1939] = "110010010101000219";
daList[1940] = "110101001010000208";
daList[1941]= "110110001010160127";
daList[1942] = "101101010101000215";
daList[1943]= "010101101010000205";
daList[1944] = "101010101101140125";
daList[1945]= "001001011101000213";
daList[1946] = "100100101101000202";
daList[1947]= "110010010101020122";
daList[1948]= "101010010101000210";
daList[1949]= "101101010101070129";
daList[1950] = "011011001010000217";
daList[1951] = "101101010101000206";
daList[1952] = "010101011010150127";
daList[1953]= "010011011010000214";
daList[1954]= "101001011011000203";
daList[1955]= "010100101011130124";
daList[1956] = "010100101011000212";
daList[1957] = "101010010101080131";
daList[1958] = "111010010101000218";
daList[1959]= "011010101010000208";
daList[1960]= "101011010101060128";
daList[1961] = "101010110101000215";
daList[1962] = "010010110110000205";
daList[1963] = "101001010111040125";
daList[1964]= "101001010111000213";
daList[1965]= "010100100110000202";
daList[1966]= "111010010011030121";
daList[1967] = "110110010101000209";
daList[1968]= "010110101010070130";
daList[1969] = "010101101010000217";
daList[1970]= "100101101101000206";
daList[1971]= "010010101110050127";
daList[1972]= "010010101101000215";
daList[1973]= "101001001101000203";
daList[1974]= "110100100110040123";
daList[1975]= "110100100101000211";
daList[1976]= "110101010010080131";
daList[1977]= "101101010100000218";
daList[1978]= "101101101010000207";
daList[1979]= "100101101101160128";
daList[1980]="100101011011000216";
daList[1981]="010010011011000205";
daList[1982]="101011001011040125";
daList[1983]="101001001011000213";
daList[1984]="1011001001110a0202";
daList[1985]="011010100101000220";
daList[1986]="011011010100000209";
daList[1987]="101011011010060129";
daList[1988]="101010110110000217";
daList[1989]="100100110111000206";
daList[1990]="010010010111050127";
daList[1991]="010010010111000215";
daList[1992]="011001001011000204";
daList[1993]="011010100101030123";
daList[1994]="111010100101000210";
daList[1995]="011010110010080131";
daList[1996]="010110101100000219";
daList[1997]="101010110110000207";
daList[1998]="100101101101050128";
daList[1999]="100100101110000216";
daList[2000]="110010010110000205";
daList[2001]="110101001010040124";
daList[2002]="110101001010000212";
daList[2003]="110110100101000201";
daList[2004]="010110101010020122";
daList[2005]="010101101010000209";
daList[2006]="101010111011070129";
daList[2007]="001001011101000218";
daList[2008]="100100101101000207";
daList[2009]="110010101011050126";
daList[2010]="101010010101000214";
daList[2011]="101101001010000203";
daList[2012]="101110101010040123";
daList[2013]="101011010101000210";
daList[2014]="010101011101090131";
daList[2015]="010010111010000219";
daList[2016]= "101001011011000208";
daList[2017]= "010100010111160128";
daList[2018]= "010100101011000216";
daList[2019]= "101010010011000205";
daList[2020]= "011110010101040125";
daList[2021]= "011010101010000212";
daList[2022]= "101011010101000201";
daList[2023]= "010110110101020122";
daList[2024]= "010010110110000210";
daList[2025]= "101001101110060129";
daList[2026]= "101001001110000217";
daList[2027]= "110100100110000206";
daList[2028]= "111010100110050126";
daList[2029]= "110101010011000213";
daList[2030]= "010110101010000203";
daList[2031] = "011101101010030123";
daList[2032]= "100101101101000211";
daList[2033] = "010010111101070131";
daList[2034]= "010010101101000219";
daList[2035] = "101001001101000208";
daList[2036]= "110100001011060128";
daList[2037]= "110100100101000215";
daList[2038] = "110101010010000204";
daList[2039] = "110111010100050124";
daList[2040]= "101101011010000212";
daList[2041]= "010101101101000201";
daList[2042]= "010101011011020122";
daList[2043]= "010010011011000210";
daList[2044]= "101001010111070130";
daList[2045]= "101001001011000217";
daList[2046]= "101010100101000206";
daList[2047] = "101100100101150126";
daList[2048] = "011011010010000214";
daList[2049] = "101011011011000202";
daList[2050]= "011101101010050124";
daList[2051]= "100100110111000211";
daList[2052]= "010010011111080201";
daList[2053] = "010010010111000219";
daList[2054]= "011001001011000208";
daList[2055] = "011010001010160128";
daList[2056] = "111010100101000215";
daList[2057]= "011010110010000204";
daList[2058] = "101001111100140124";
daList[2059] = "101010101110000212";
daList[2060]= "100100101110000202";
daList[2061]= "110100101110030121";
daList[2062] = "110010010110000209";
daList[2063] = "110101010101070129";
daList[2064]= "110101001010000217";
daList[2065] = "110110100101000205";
daList[2066]= "010111010101050126";
daList[2067] = "010101101010000214";
daList[2068]= "101001101101000203";
daList[2069]= "010101011101040123";
daList[2070]= "010101101101000211";
daList[2071] = "101010011011080131";
daList[2072] = "101010010101000219";
daList[2073]= "101101001010000207";
daList[2074] = "101101101010060127";
daList[2075] = "101011010101000215";
daList[2076] = "010101011010000205";
daList[2077] = "101010111010040124";
daList[2078]= "101001011011000212";
daList[2079]= "010100101011000202";
daList[2080] = "101100100111030122";
daList[2081]= "011010010011000209";
daList[2082] = "011100110011070129";
daList[2083] = "011010101010000217";
daList[2084]= "101011010101000206";
daList[2085] = "010010110101150126";
daList[2086]= "010010110110000214";
daList[2087]= "101001010111000203";
daList[2088]= "010101001110040124";
daList[2089] = "110100010110000210";
daList[2090]= "111010010110080130";
daList[2091]= "110101010010000218";
daList[2092] = "110110101010000207";
daList[2093]= "011010101010060127";
daList[2094] = "010101101101000215";
daList[2095]= "010010101110000205";
daList[2096]= "101010011101040125";
daList[2097] = "101001001101000212";
daList[2098] = "110100010101000201";
daList[2099] = "111100100101020121";
daList[2100] = "110101010010000209";
return;
}
//**** END ****
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。