您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 儒略日、公历年月日之间的转换以及儒略日的应用电子教案
精品文档精品文档一、作业要求编写程序实现以下任务:1.1由公历年月日化为儒略日1.2由儒略日转化为公历年月日1.3儒略日的应用1.3.1计算两个日期间的间隔天数1.3.2计算星期几1.3.3计算年积日(DOY)1.3.4由年积日计算年月日二、程序设计2.1窗体设计精品文档精品文档2.2代码实现2.2.1由公历年月日化为儒略日//由公历年月日转化为儒略日的函数publicdoubleGLToJD(doubleY,doubleM,doubleD){doubleJDtime;JDtime=367*Y-Math.Truncate(7*(Y+Math.Truncate((M+9)/12))/4)+Math.Truncate(275*M/9)+D+1721013.5;returnJDtime;}2.2.2由儒略日转化为公历年月日//由儒略日转化为公历年月日的函数publicvoidJDToGL(doubleJDtime,outdoubleY,outdoubleM,outdoubleD){doublea,b,c,d,e;a=Math.Truncate(JDtime+0.5);b=a+1537;c=Math.Truncate((b-122.1)/365.25);d=Math.Truncate(365.25*c);e=Math.Truncate((b-d)/30.6001);D=b-d-Math.Truncate(30.6001*e)+JDtime+0.5-Convert.ToInt32(JDtime+0.5);M=e-1-Math.Truncate(e/14)*12;Y=c-4715-Math.Truncate((7+M)/10);}2.2.3计算两个日期间的间隔天数privatevoidJGTSbutton_Click(objectsender,EventArgse){doubleJDtime1,JDtime2,Y1,M1,D1,Y2,M2,D2,JGTS;if(Year31.Text==||Month31.Text==||Day31.Text==||Year31.Text==||Month31.Text==||Day31.Text==){MessageBox.Show(输入的日期不能为空!);}else{Y1=double.Parse(Year31.Text);M1=double.Parse(Month31.Text);D1=double.Parse(Day31.Text);JDtime1=GLToJD(Y1,M1,D1);精品文档精品文档Y2=double.Parse(Year32.Text);M2=double.Parse(Month32.Text);D2=double.Parse(Day32.Text);JDtime2=GLToJD(Y2,M2,D2);JGTS=Math.Abs(JDtime2-JDtime1);JG.Text=JGTS.ToString();}}2.2.4计算星期几privatevoidXQbutton_Click(objectsender,EventArgse){doubleJDtime,Y,M,D,XQ;if(Year4.Text==||Month4.Text==||Day4.Text==){MessageBox.Show(输入的日期不能为空!);}else{Y=double.Parse(Year4.Text);M=double.Parse(Month4.Text);D=double.Parse(Day4.Text);JDtime=GLToJD(Y,M,D);XQ=(JDtime+1.5)%7;if(XQ==0){weekDay.Text=星期日;}if(XQ==1){weekDay.Text=星期一;}if(XQ==2){weekDay.Text=星期二;}if(XQ==3){weekDay.Text=星期三;}if(XQ==4){weekDay.Text=星期四;}精品文档精品文档if(XQ==5){weekDay.Text=星期五;}if(XQ==6){weekDay.Text=星期六;}}}2.2.5计算年积日privatevoidNJRbutton_Click(objectsender,EventArgse){doubleY,M,D,JDtime1,JDtime2;if(Year5.Text==||Month5.Text==||Day5.Text==){MessageBox.Show(输入的日期不能为空!);}else{Y=double.Parse(Year5.Text);M=double.Parse(Month5.Text);D=double.Parse(Day5.Text);JDtime1=GLToJD(Y,M-1,D);JDtime2=GLToJD(Y,0,0);NJR1.Text=(JDtime1-JDtime2).ToString();}}2.2.6由年积日计算年月日privatevoidNJRTONYRbutton_Click(objectsender,EventArgse){doubleJDtime,Y1,Y,M,D,NJR;if(Year6.Text==||NJR2.Text==){MessageBox.Show(输入的日期不能为空!);}else精品文档精品文档{NJR=double.Parse(NJR2.Text);Y1=double.Parse(Year6.Text);JDtime=GLToJD(Y1,0,0)+NJR+30;JDToGL(JDtime,outY,outM,outD);textBox1.Text=JDtime.ToString();GLNYR.Text=Y.ToString()+年+M.ToString()+月+D.ToString()+日;}}2.3运行结果精品文档精品文档精品文档精品文档
本文标题:儒略日、公历年月日之间的转换以及儒略日的应用电子教案
链接地址:https://www.777doc.com/doc-5360096 .html