简易日历代码
C语言万年历代码
题目:年历显示。
功能要求:(1)输入一个年份,输出是在屏幕上显示该年的日历。
假定输入的年份在1940-2040年之间。
(2)输入年月,输出该月的日历。
(3)输入年月日,输出距今天还有多少天,星期几,是否是公历节日。
如下图:以下部分为代码:#include<stdio.h>#include<math.h>void part1(int x); //函数1~6为打印日历的函数void part2(int x);void part3(int x);void part4(int x);void part5(int x);void part6(int x);int weak(int x,int y); //计算1号对应的星期int weak2(int x,int y,int z); //计算星期,为函数day提供数据int year(int x); //打印日历的函数int mouth(int x); //打印月历的函数int day(int x); //查询天数的函数int distance(int x,int y,int z); //提供距离天数查询int main(){int a;char z;printf("****************************************************************\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" * 欢迎使用万年历!*\n");printf(" * *\n");printf(" * *\n");printf(" * 开发:杨润*\n");printf("****************************************************************\n");x: //位置标注printf("\n");printf("请输入一个日期(Ex:20150302或201503或2015):");scanf("%d",&a);printf("\n");if((1940<=a)&&(a<=2040)){year(a);}else if((194001<=a)&&(a<=204012)){mouth(a);}else if((19400101<=a)&&(a<=20401231)){day(a);}else{printf("输入错误,请重新输入!");goto x;}printf("\n");printf("\n");printf("继续查询(y),退出(n):");scanf("%s",&z);if(z=='y'){goto x;}else{;}return 0;}int year(int x){printf("-------------------------------%d年的年历----------------------------\n",x);printf("\n");part1(x); //调用第一部分函数part2(x);part3(x);part4(x);part5(x);part6(x);printf("-----------------------------------------------------------------------\n");return 0;}int mouth(int x){int i,n,y,y2,w,week,yue2,bz1; //n表示年份,y表示月份,w,y2均为临时变量,yue2表示2月份天数n=(int)(x/100);y=(int)(x%100);printf("您现在查询的是%d年%d月\n",n,y);printf(" \n");if(y==1) //1月的情况{printf("1月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的1.1星期{y2=(n-1)%100; //y2 w=(int)(y2+(y2/4)+(19/4)-38+(26*1.4));week=w%7;}if(n>=2000) //计算大于两千的1.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.4));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的一月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if(y==2) //2月的情况{if(n%4==0){if(n%100!=0)yue2=29;else if(n%100==0&&n%400==0)yue2=29;elseyue2=28;}else{yue2=28;}printf("2月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的2.1星期{y2=(n-1)%100; //y2w=(int)(y2+(y2/4)+(19/4)-38+(26*1.5));week=w%7;}if(n>=2000) //计算大于两千的2.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.5));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的2月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1=yue2){printf(" ");}bz1=bz1+1;}printf("\n");}//2月情况判断完毕if((y==3)||(y==5)||(y==7)||(y==8)||(y==10)||(y==12)) //31天的情况(3、5、7、8、10、12月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if((y==4)||(y==6)||(y==9)||(y==11)) //30天的情况(4、6、9、11月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");}return 0;}int day(int x){int n,y,y1,t,week; //n为年,y为yue,y1位计算y的临时变量,t为天,week为周,p为距离今天天数n=x/10000;y1=x%10000;y=y1/100;t=x%100;printf("\n");printf("您查询的是:%d年%d月%d日",n,y,t);week=weak2(n,y,t);switch(week) //根据返回数值判断星期{case 0:printf("星期日");break;case 1:printf("星期一");break;case 2:printf("星期二");break;case 3:printf("星期三");break;case 4:printf("星期四");break;case 5:printf("星期五");break;case 6:printf("星期六");break;}if(y==1&&t==1) printf("这天是元旦"); //查询节日if(y==2&&t==2) printf("这天是世界湿地日");if(y==2&&t==14) printf("这天是情人节");if(y==3&&t==3) printf("这天是全国爱耳日");if(y==3&&t==5) printf("这天是青年志愿者服务日");if(y==3&&t==8) printf("这天是国际妇女节");if(y==3&&t==9) printf("这天是保护母亲河日");if(y==3&&t==12) printf("这天是中国植树节");if(y==3&&t==14) printf("这天是白色情人节\n");if(y==3&&t==14) printf("这天是国际警察日");if(y==3&&t==15) printf("这天是世界消费者权益日");if(y==3&&t==21) printf("这天是世界森林日\n");if(y==3&&t==21) printf("这天是世界睡眠日");if(y==3&&t==22) printf("这天是世界水日");if(y==3&&t==23) printf("这天是世界气象日");if(y==3&&t==24) printf("这天是世界防治结核病日");if(y==4&&t==1) printf("这天是愚人节");if(y==4&&t==5) printf("这天是清明节");if(y==4&&t==7) printf("这天是世界卫生日");if(y==4&&t==22) printf("这天是世界地球日");if(y==4&&t==26) printf("这天是世界知识产权日");if(y==5&&t==1) printf("这天是国际劳动节");if(y==5&&t==3) printf("这天是世界哮喘日");if(y==5&&t==4) printf("这天是中国青年节");if(y==5&&t==8) printf("这天是世界红十字日");if(y==5&&t==12) printf("这天是国际护士节");if(y==5&&t==15) printf("这天是国际家庭日");if(y==5&&t==17) printf("这天是世界电信日");if(y==5&&t==20) printf("这天是全国学生营养日");if(y==5&&t==23) printf("这天是国际牛奶日");if(y==5&&t==31) printf("这天是世界无烟日");if(y==6&&t==1) printf("这天是国际儿童节");if(y==6&&t==5) printf("这天是世界环境日");if(y==6&&t==6) printf("这天是全国爱眼日");if(y==6&&t==17) printf("这天是世界防治荒漠化和干旱日"); if(y==6&&t==23) printf("这天是国际奥林匹克日");if(y==6&&t==25) printf("这天是全国土地日");if(y==6&&t==26) printf("这天是国际禁毒日");if(y==7&&t==1) printf("这天是中国共产党诞生日\n");if(y==7&&t==1) printf("这天是国际建筑日");if(y==7&&t==7) printf("这天是中国人民抗日战争纪念日"); if(y==7&&t==11) printf("这天是世界人口日");if(y==8&&t==1) printf("这天是中国人民解放军建军节");if(y==8&&t==12) printf("这天是国际青年节");if(y==9&&t==8) printf("这天是国际扫盲日");if(y==9&&t==10) printf("这天是中国教师节");if(y==9&&t==16) printf("这天是中国脑健康日\n");if(y==9&&t==16) printf("这天是国际臭氧层保护日");if(y==9&&t==20) printf("这天是全国爱牙日");if(y==9&&t==21) printf("这天是世界停火日");if(y==9&&t==27) printf("这天是世界旅游日");if(y==10&&t==1) printf("这天是中华人民共和国国庆节\n");if(y==10&&t==1) printf("这天是国际音乐日\n");if(y==10&&t==1) printf("这天是国际老年人日");if(y==10&&t==4) printf("这天是世界动物日");if(y==10&&t==5) printf("这天是世界教师日");if(y==10&&t==8) printf("这天是全国高血压日");if(y==10&&t==9) printf("这天是世界邮政日");if(y==10&&t==10) printf("这天是世界精神卫生日");if(y==10&&t==14) printf("这天是世界标准日");if(y==10&&t==15) printf("这天是国际盲人节\n");if(y==10&&t==15) printf("这天是世界农村妇女日");if(y==10&&t==16) printf("这天是世界粮食日");if(y==10&&t==17) printf("这天是国际消除贫困日");if(y==10&&t==24) printf("这天是联合国日\n");if(y==10&&t==24) printf("这天是世界发展新闻日");if(y==10&&t==28) printf("这天是中国男性健康日");if(y==10&&t==29) printf("这天是国际生物多样性日");if(y==10&&t==31) printf("这天是万圣节");if(y==11&&t==8) printf("这天是中国记者节");if(y==11&&t==9) printf("这天是消防宣传日");if(y==11&&t==14) printf("这天是世界糖尿病日");if(y==11&&t==17) printf("这天是国际大学生节");if(y==11&&t==25) printf("这天是国际消除对妇女的暴力日");if(y==12&&t==1) printf("这天是世界爱滋病日");if(y==12&&t==3) printf("这天是世界残疾人日");if(y==12&&t==4) printf("这天是全国法制宣传日");if(y==12&&t==9) printf("这天是世界足球日");if(y==12&&t==25) printf("这天是圣诞节");if(y==12&&t==29) printf("这天是国际生物多样性日");printf("\n");distance(n,y,t);return 0;}//计算今天日期的函数结尾void part1(int x) //第一部分{int i,week,week2,y,w,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增b1=7;printf("1月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("7月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.4));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.4));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束} //第一部分1月、7月打印完毕!void part2(int x) //第二部分2月、8月开始打印!//第二部分{int i,week,week2,y,w,b1,bz1,bz2,yue2;//week,week2用于计算2.1的星期,bz1和bz2为日期的递增b1=8; //表示当前部分的月份printf("2月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("8月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x%4==0){if(x%100!=0)yue2=29;else if(x%100==0&&x%400==0)yue2=29;elseyue2=28;}else{yue2=28;}if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.5));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.5));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第一行for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //2月份的第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part3(int x) //第三部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=3,b1=9; //表示当前不封的月份printf("3月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("9月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(3.1)week2=weak(x,b1); //调用计算星期的函数(8.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part4(int x) //第四部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=4,b1=10; //表示当前不封的月份printf("4月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("10月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(4.1)week2=weak(x,b1); //调用计算星期的函数(10.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印4月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的10月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的4月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part5(int x) //第五部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=5,b1=11; //表示当前不封的月份printf("5月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("11月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(11.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10)bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31)bz1=bz1+1;}printf(" "); //从这里开始打印11月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part6(int x) //第六部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=6,b1=12; //表示当前不封的月份printf("6月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("12月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(12.1)for(i=0;i<week;i++){printf(" ");}。
几款漂亮日历代码
几款漂亮日历代码这些日历代码你可放心使用,直接将代码贴入自定义模块发表即可!新版网易博客怎样添加自定义模块?请点击下面地址参考:/blog/static/723372542010101 645915447/代码1、显示农历和时间<EMBED src=/flash/f10/1/4.swf width=550 height=400 type=application/x-shockwave-flash></EMBED>代码2、显示每月大事记<EMBED src=/flash/f10/1/10.swf width=550 height=400 type=application/x-shockwave-flash></EMBED>代码3、时钟日历<EMBED height=210 type=application/x-shockwave-flash pluginspage=/go/getflashplayer width=210 src=" " wmode="transparent" autostart="0" allowNetworking="internal" allowScriptAccess="never"> 代码4、鱼儿水中游<embed id=show_swf1 src="/swf/3_.swf" width="183" height="202" wmode="transparent" type="application/x-shockwave-flash">代码5、显示黄历、星座等<P align=center><EMBED style="WIDTH: 200px; HEIGHT:400px" src=/flash/Mini365.swf width=200 height=400 type=application/x-shockwave-flash allowScriptAccess="never" allowNetworking="internal"FlashVars="&usrbday=0724&cusAry=247%40HBO%E6%9C%AC %E5%91%A8%E7%94%B5%E5%BD%B1%E3%80%A5605%40%E 8%8D%89%E6%A0%B9%E7%B2%BE%E5%93%81%E3%80%A52 51%40%E6%AF%8F%E6%97%A5%E6%95%85%E4%BA%8B%E3 %80%A5315%40%E6%AF%8F%E6%97%A5%E8%8B%B1%E8%A F%AD&widget=163&mainbgcolor=%23eafb32"wmode="transparent"></P>代码6、显示重要节日的日历<P align=center><EMBED style="MARGIN: 5px" pluginspage=/go/getflashplayer src=/flash/flex365.swf?&usrbday=0101&cusAry=247%40HBO% E6%9C%AC%E5%91%A8%E7%94%B5%E5%BD%B1%E3%80%A5 155%40%E8%B6%B3%E7%90%83%E7%9B%B4%E6%92%AD%E 8%A1%A8%E3%80%A592%40NBA%E8%B5%9B%E7%A8%8B%E 3%80%A5605%40%E8%8D%89%E6%A0%B9%E7%B2%BE%E5% 93%81%E3%80%A5251%40%E6%AF%8F%E6%97%A5%E6%95% 85%E4%BA%8B%E3%80%A5315%40%E6%AF%8F%E6%97%A5 %E8%8B%B1%E8%AF%AD&widget=other&mainbgcolor=%230 0DD00 width=527 height=300 type=application/x-shockwave-flash wmode="transparent" invokeURLs="false" quality="high" allowScriptAccess="never"allowNetworking="internal"></EMBED></P>代码7、显示时间的万年历<P align=center><TABLE borderColor=#ffffff height=0 cellSpacing=0borderColorDark=#54461c cellPadding=0 width=500 borderColorLight=#a89a6fbackground=/DownloadImg/2011/0 2/2115/9355384_1.gif border=4><TBODY><TR><TD><P align=center><EMBED style="MARGIN: 5px" pluginspage=/go/getflashplayer src=/flash/flash/moniren86345.swf width=480 height=380 type=application/x-shockwave-flash wmode="transparent" quality="high"allowscriptaccess="never"></EMBED></P></TD></TR></TBO DY></TABLE></P>。
c日历源代码
#include <stdio.h>#include <windows.h>void month(int a)//输出月份和星期{printf("\t");switch (a){case 1:printf("Janurary 1\t\t\t\t");case 2:printf("February 2");break;case 3:printf("March 3 \t\t\t\t");case 4:printf("April 4");break;case 5:printf("May 5 \t\t\t\t");case 6:printf("June 6");break;case 7:printf("July 7 \t\t\t\t");case 8:printf("August 8");break;case 9:printf("September 9 \t\t\t");case 10:printf("October 10");break;case 11:printf("November 11 \t\t\t");case 12:printf("December 12");break;}printf("\n\t");printf("Sun Mon Tue Wed Thu Fri Sat\t\t");printf("Sun Mon Tue Wed Thu Fri Sat\n\t");}int date(int a,int b,int c)//输出日期a为月份b为判断润平年r为某月最后一天的星期数{void space(int a);int i,j,n,m,x=1,y,k=0;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 9:n=30;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){printf("%2d ",i);if (j==7 && i!=n){j=0;printf("\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;space(c);y=c;k=1;if (y<1)y=1;}printf("%2d ",x);if (y==7 && x!=m){x++;printf("\n\t");y=0;break;}if (x==m && y==7){x++;printf("\n\t");y=0;break;}if (x==m && y!=7)printf("\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){printf(" ");j=1+j;}printf("\t\t");if (x<=m)for (y=1;x<=m;y++,x++){printf("%2d ",x);if (y==7 && x!=m){printf("\n\t\t\t\t\t\t");y=0;}}printf("\n\t===========================\t\t");printf("===========================\n\n");if (y>7 || y==0)y=1;return y;}int leap(int a)//判断是否为闰年{int n;if ((a%4==0 && a%100!=0) || a%400==0)n=1;elsen=0;return n;}int print()//输出日历{void shxi(int a);void ganzhi(int a);void space(int a);int n,days,year,result,r,i,week,rem;while (1){printf("\t\t请输入年份:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色i=scanf("%d",&year);if (i==1){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);break;}elsefflush(stdin);printf("\t\t错误输入!\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);}ganzhi(year);shxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;//一月一号星期几的判断公式r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;//计算这一年有多少周printf("\t\t\t\t\t%d周\n",week);printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){month(i);space(r);r=date(i,n,r);}printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");return 0;}void space(int a)//输出空格{int i;for (i=0;i<a-1;i++)printf(" ");}int main()//主程序输出选择菜单{void fprint();int n;system("color f0");//设置背景和字体颜色do{printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t*\t1---查询(Search) *\n");printf("\t\t*\t2---导出(Lead) *\n");printf("\t\t*\t0---关闭(Close) *\n");printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t请选择:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色scanf("%d",&n);system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);switch (n){case 1:print();break;case 2:fprint();break;case 0:break;default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);printf("\ t\t错误选择!请重选");}fflush(stdin);printf("\n");} while(n!=0);return 0;}void shxi(int a)//判断这一年的属性并输出{int s;if (a>=2008) //属性判断公式s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:printf("鼠");break;case 2:printf("牛");break;case 3:printf("虎");break;case 4:printf("兔");break;case 5:printf("龙");break;case 6:printf("蛇");break;case 7:printf("马");break;case 8:printf("羊");break;case 9:printf("猴");break;case 10:printf("鸡");break;case 11:printf("狗");break;case 12:printf("猪");break;}}void ganzhi(int a)//判断天干地支{int g,z;g=(a-3)%10;//天干判断公式z=(a-3)%12;//地支判断公式printf("\t\t\t");switch (g){case 1:printf("甲");break;case 2:printf("乙");break;case 3:printf("丙");break;case 4:printf("丁");break;case 5:printf("戊");break;case 6:printf("己");break;case 7:printf("庚");break;case 8:printf("辛");break;case 9:printf("壬");break;case 0:printf("癸");break;}switch (z){case 1:printf("子");break;case 2:printf("丑");break;case 3:printf("寅");break;case 4:printf("卯");break;case 5:printf("辰");break;case 6:printf("巳");break;case 8:printf("未");break;case 9:printf("申");break;case 10:printf("酉");break;case 11:printf("戌");break;case 0:printf("亥");break;}printf("年\t");}FILE *fp;//定义文件指针void fmonth(int a)//导出月份和星期{fprintf(fp,"\t");switch (a){case 1:fprintf(fp,"Janurary 1\t\t\t\t");case 2:fprintf(fp,"February 2");break;case 3:fprintf(fp,"March 3 \t\t\t\t");case 4:fprintf(fp,"April 4");break;case 5:fprintf(fp,"May 5 \t\t\t\t");case 6:fprintf(fp,"June 6");break;case 7:fprintf(fp,"July 7 \t\t\t\t");case 8:fprintf(fp,"August 8");break;case 9:fprintf(fp,"September 9 \t\t\t");case 10:fprintf(fp,"October 10");break;case 11:fprintf(fp,"November 11 \t\t\t");case 12:fprintf(fp,"December 12");break;}fprintf(fp,"\n\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\t\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\n\t"); }int fdate(int a,int b,int c)//导出日期{int i,j,n,m,x=1,y,k=0,r;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){fprintf(fp,"%2d ",i);if (j==7 && i!=n){j=0;fprintf(fp,"\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;for (r=0;r<c-1;r++)fprintf(fp," ");y=c;k=1;if (y<1)y=1;}fprintf(fp,"%2d ",x);if (y==7 && x!=m){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y==7){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y!=7)fprintf(fp,"\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){fprintf(fp," ");j=1+j;}fprintf(fp,"\t\t");if (x<=m)for (y=1;x<=m;y++,x++){fprintf(fp,"%2d ",x);if (y==7 && x!=m){fprintf(fp,"\n\t\t\t\t\t\t");y=0;}}fprintf(fp,"\n\t===========================\t\t");fprintf(fp,"===========================\n\n");if (y>7 || y==0)y=1;return y;}void fprint()//导出文件{void fshxi(int a);void fganzhi(int a);void fspace(int a);int n,days,year,result,r,i,week,rem;char filename[10],type[]=".txt";while (1){printf("\t\t请输入年份:");i=scanf("%d",&year);if (i==1)break;elsefflush(stdin);printf("\t\t错误输入!\n");}printf("\t\t请输入导出文件名:");scanf("%s",&filename);fp=fopen(strcat(filename,type),"w");//以写的方式打开文件fganzhi(year);fshxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;fprintf(fp,"\t\t\t\t\t\t\t\t%d周\n",week);fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){fmonth(i);fspace(r);r=fdate(i,n,r);}fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");fclose(fp);//关闭文件printf("\t\t已导出完成");}void fspace(int a)//导出空格{int i;for (i=0;i<a-1;i++)fprintf(fp," ");}void fshxi(int a)//导出属性{int s;if (a>=2008)s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:fprintf(fp,"鼠");break;case 2:fprintf(fp,"牛");break;case 3:fprintf(fp,"虎");break;case 4:fprintf(fp,"兔");break;case 5:fprintf(fp,"龙");break;case 6:fprintf(fp,"蛇");break;case 7:fprintf(fp,"马");break;case 8:fprintf(fp,"羊");break;case 9:fprintf(fp,"猴");break;case 10:fprintf(fp,"鸡");break;case 11:fprintf(fp,"狗");break;case 12:fprintf(fp,"猪");break;}fprintf(fp,"\n");}void fganzhi(int a)//导出天干地支{int g,z;g=(a-3)%10;z=(a-3)%12;fprintf(fp,"\t\t\t%d年\t\t",a);switch (g){case 1:fprintf(fp,"甲");break;case 2:fprintf(fp,"乙");break;case 3:fprintf(fp,"丙");break;case 4:fprintf(fp,"丁");break;case 5:fprintf(fp,"戊");break;case 6:fprintf(fp,"己");break;case 7:fprintf(fp,"庚");break;case 8:fprintf(fp,"辛");break;case 9:fprintf(fp,"壬");break;case 0:fprintf(fp,"癸");break;}switch (z){case 1:fprintf(fp,"子");break;case 2:fprintf(fp,"丑");break;case 3:fprintf(fp,"寅");break;case 4:fprintf(fp,"卯");break;case 5:fprintf(fp,"辰");break;case 6:fprintf(fp,"巳");break;case 7:fprintf(fp,"午");break;case 8:fprintf(fp,"未");break;case 9:fprintf(fp,"申");break;case 10:fprintf(fp,"酉");break;case 11:fprintf(fp,"戌");break;case 0:fprintf(fp,"亥");break;}fprintf(fp,"年\t");}。
日历源代码
日历源代码#include<stdio.h>int leapyear(int year);int week_of_newyears_day(int year);int main(){int year = 0;int month = 0;int day = 0;int len_of_month = 0;int i = 0;int t = 0;while(1){printf("请输入某年年份: ");scanf("%d",&year);if(year!=0){t = week_of_newyears_day(year);printf("\n %d年\n\n",year); /* 打印年份*/for(month=1; month<=12;month=month+1) /* 打印12个月的月历*/{printf(" %d月份\n",month);printf("星期日星期一星期二星期三星期四星期五星期六\n");for(i=0;i<t;i=i+1)/* 找当月1日的打印位置*/{printf(" ");}if(month==4 || month== 6 || month==9 || month==11)len_of_month = 30;else if(month==2){if(leapyear(year))len_of_month = 29;elselen_of_month = 28;}elselen_of_month = 31;for(day=1;day<=len_of_month;day=day+1)/* 打印当月日期*/{printf(" %2d ",day);t = t+1;if(t == 7)/* 打满一星期应换行*/{t = 0;printf("\n");}}printf("\n\n");/* 打完一月应换行*/ }}else if(year==0){break;}}return 0;}int leapyear(int year){int leap = 0;if((year%4==0 && year%100!=0 )|| year%400==0) {leap = 1;}return leap;}int week_of_newyears_day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7;return b;}else{a=year-2000;//b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6;b = ((a/4 + 1) * 366 + (a - a/4 - 1) * 365) % 7 + 6; return b%7;}}运行结果:。
日历实现vb代码
日历实现vb代码Dim tian, di As StringDim cyear, cmonth, cday As Integer Dim year1, month1, day1 As Integer Dim n, k, i, j As IntegerDim total As LongDim date1, date2 As DateDim IsendAs BooleanDim st As StringDim data(100) As StringDim yueDim temp As IntegerPrivate Sub Combo2_click()year1 = Val(Combo2.Text)month1 = Val(Combo1.Text)day1 = 1Isend = Falsek = 0n = 0x = cal()Label2.Caption = disp2()Label3.Caption = f()Label4.Caption = redisp()End SubPrivate Sub Combo1_click()year1 = Val(Combo2.Text)month1 = Val(Combo1.Text)day1 = 1Isend = Falsek = 0n = 0x = cal()Picture1.ClsPicture1.Print redisp()Label2.Caption = disp2()End SubPrivate Sub Form_Initialize()'以字符串形式统计农历信息,data(0) = "101001001011" data(1) = "51011001001011" data(2) = "011010100101" data(3) = "011011010100" data(4) = "41010110110101" data(5) = "001010110110" data(6) = "100101010111" data(7) = "20100100101111" data(8) = "010*********" data(9) = "60110010010110" data(10) = "110101001010" data(11) = "111010100101" data(12) = "50110110101001" data(13) = "010*********" data(14) = "001010110110" data(15) = "31001001101110" data(16) = "100100101110" data(17) = "71100100101101" data(18) = "110010010101" data(19) = "110101001010" data(20) = "61101101001010" data(21) = "101101010101" data(22) = "010*********" data(23) = "41010101011011" data(24) = "001001011101" data(25) = "100100101101" data(26) = "21100100101011" data(27) = "101010010101" data(28) = "71011010010101" data(29) = "011011001010" data(30) = "101101010101" data(31) = "50101010110101" data(32) = "010*********" data(33) = "101001011011" data(34) = "30101001010111" data(35) = "010*********" data(36) = "81010100101010" data(37) = "111010010101" data(38) = "011010101010" data(39) = "61010110101010"data(41) = "010*********" data(42) = "41010010101110" data(43) = "101001010111" data(44) = "010*********" data(45) ="31110100100110" data(46) = "110110010101" data(47) = "70101101010101" data(48) = "010*********" data(49) = "100101101101" data(50) = "50100101011101" data(51) = "010*********" data(52) = "101001001101" data(53) = "41101001001101" data(54) = "110100100101" data(55) = "81101010100101" data(56) = "101101010100" data(57) = "101101101010" data(58) = "61001011011010" data(59) = "100101011011" data(60) = "010*********" data(61) = "41010010010111" data(62) = "101001001011" data(63) = "A1011001001011" data(64) = "011010100101" data(65) = "011011010100" data(66) = "61010110110100" data(67) = "101010110110" data(68) = "100101010111" data(69) = "50100100101111" data(70) = "010*********" data(71) = "011001001011" data(72) = "30110101001010" data(73) = "111010100101" data(74) = "80110101100101" data(75) = "010*********" data(76) = "101010110110" data(77) = "51001001101101" data(78) = "100100101110" data(79) = "110010010110" data(80) = "41101010010101" data(81) = "110101001010" data(82) = "110110100101" data(83) = "20101101010101"data(85) = "71010101011011"data(86) = "001001011101"data(87) = "100100101101"data(88) = "51100100101011"data(89) = "101010010101"data(90) = "101101001010"data(91) = "41011010101010"data(92) = "101011010101"data(93) = "90101010110101"data(94) = "010*********"data(95) = "101001011011"data(96) = "60101001010111"data(97) = "010*********"data(98) = "101010010011"data(99) = "40111010010101"year1 = Year(Now)month1 = Month(Now)day1 = Day(Now)x = calLabel1.Caption = disp3()End SubPrivate Sub Form_Load()For j = 0 To 11Combo1.List(j) = j + 1Next jFor i = 0 To 99Combo2.List(i) = i + 1921Next iCombo1.T ext = Combo1.List(Month(Now) - 1) Combo2.Text = Combo2.List(Year(Now) - 1921) tian = "甲乙丙丁戊己庚辛壬癸"di = "子丑寅卯辰巳午未申酉戌亥"Isend = Falsek = 0n = 0year1 = Year(Now)month1 = Month(Now)day1 = 1x = calLabel2.Caption = disp2() '天干地支纪年Form1.ShowPicture1.Print redisp() '显示农历阳历在图片框上Label5.Caption = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"End SubFunction disp1() As String '以汉字形式显示农历信息ri1 = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九廿十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"yue = Array("一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊")st = ""st = st + Mid(ri1, 2 * cday - 1, 2)If cday = 1 ThenIf cmonth< 0 Thenst = "闰" &yue(-cmonth - 1)Elsest = yue(cmonth - 1) & "月"End IfEnd Ifdisp1 = stEnd FunctionFunction disp2() As String '天干地支纪年法Dim tmp As Stringtmp = ""tmp = Mid(tian, ((Year(Now) - 4) Mod 10) + 1, 1) + Mid(di, ((Year(Now) - 4) Mod 12) + 1, 1) & "年" disp2 = tmpEnd FunctionFunction disp3() As String '把农历信息以汉字的形式输出ri1 = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九廿十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"yue = Array("一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊")If cmonth< 0 Thenst = "闰" &yue(-cmonth - 1) & "月"Elsest = yue(cmonth - 1) & "月"End Ifst = st + Mid(ri1, 2 * cday - 1, 2)disp3 = stEnd FunctionFunction cal() As String '以1921年2月8日为基准点,计算阳历某一天对应的阴历k = 0: n = 0: total = 0date1 = DateSerial(year1, month1, day1)date2 = #2/8/1921#total = DateDiff("d", date2, date1) + 1Dot = data(k)n = IIf(Len(t) = 14, 2, 1)i = (2 * (n - 1) + 13)DoIf total <= 29 + Val(Mid(t, n, 1)) ThenIsend = TrueExit DoEnd Iftotal = total - 29 - Val(Mid(t, n, 1))n = n + 1temp = nIf (n = i) ThenEnd IfLoopIf (Isend = True) ThenExit DoEnd Ifk = k + 1Loopcyear = 1921 + kcmonth = ncday = totalIf Len(data(k)) = 14 ThenIf (cmonth>Val(Mid(data(k), 1, 1)) + 2) Thencmonth = cmonth - 2ElseIf cmonth = Val(Mid(data(k), 1, 1)) + 2 Thencmonth = 2 - cmonthElsecmonth = cmonth - 1End IfEnd IfEnd IfEnd FunctionFunction redisp() As String '把阳历和农历放到一块以字符串的形式的组合到一起redisp = " 日" + "一" + "二" + "三" + "四" + "五" + "六" + Chr(13) + Chr(13)date1 = DateSerial(year1, month1, day1)s = Weekday(date1)Dim a As IntegerFor i = 1 To s - 1redisp = redisp + Space(7)NextFor i = 1 To days(month1)Call addredisp = redisp + " " + Format(i, "!@@@@@") If a Mod 7 = 0 Andi< 8 Thenredisp = redisp + Chr(13)For j = 1 To s - 1redisp = redisp + Space(7)NextFor b = s To 7redisp = redisp + disp1() + " "cday = cday + 1Call addNext bredisp = redisp + Chr(13) + Chr(13)ElseIf (a Mod 7 = 0 Andi>= 8) Thenredisp = redisp + Chr(13)For j = i - 6 Toiredisp = redisp + disp1() + " "cday = cday + 1Call addNext jredisp = redisp + Chr(13) + Chr(13)End IfIf i = days(month1) And a <> 0 Thenredisp = redisp + Chr(13)For j = 1 To aredisp = redisp + disp1() + " "cday = cday + 1Call addNext jEnd Ifa = (a + 1) Mod 7NextEnd FunctionFunction days(month1) As Integer '判断阳历每个月的天数Select Case month1Case 1, 3, 5, 7, 8, 10, 12days = 31Case 4, 6, 9, 11days = 30Case 2If (year1 Mod 4 = 0 And year1 Mod 100 <> 0) Or (year1 Mod 400 = 0) Thendays = 29Elsedays = 28End IfEnd SelectEnd FunctionPrivate Sub Timer1_Timer() '调用系统时间,显示时分秒Label6.Caption = Format(Hour(Time) & ":" & Minute(Time) & ":" & Second(Time), "hh:mm:ss") End SubSub add() '农历的日期加一天之后的农历If Len(data(cyear - 1921)) = 12 ThenIf cday> 29 + Val(Mid(data(cyear - 1921), cmonth, 1)) Then cday = 1: cmonth = cmonth + 1If cmonth = 13 Then cmonth = 1: cyear = cyear + 1 End IfElseIfLen(data(cyear - 1921)) = 14 ThenSelect Case cmonthCase Is < 0If cday> 29 + Val(Mid(data(cyear - 1921), -cmonth + 2, 1)) Then cday = 1: cmonth = -cmonth + 1End IfCase Is <="" 1,="" 1921),="" bdsfid="281" p="">If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 1, 1)) Then cday = 1: cmonth = cmonth + 1End IfCase Is = V al(Mid(data(cyear - 1921), 1, 1))If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 1, 1)) Then cday = 1: cmonth = -cmonthEnd IfCase Is >Val(Mid(data(cyear - 1921), 1, 1))If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 2, 1)) Then cday = 1: cmonth = cmonth + 1End IfEnd SelectEnd IfEnd Sub。
日历代码_精品文档
日历代码
1. 简介
日历是用来显示日期的一种工具。
在计算机编程中,我们可以通过编写代码来生成和显示日历。
本文将介绍如何用Python编写一个简单的日历代码。
我们将使用Python的datetime和calendar模块来实现这个功能。
2. 实现步骤
2.1 导入模块
我们首先需要导入Python的datetime和calendar模块。
datetime模块提供了日期和时间的相关功能,而calendar模块则提供了生成日历的功能。
import datetime
import calendar
2.2 获取当前日期
我们可以使用datetime模块的date类来获取当前日期。
today = datetime.date.today()
2.3 获取当前月份的日历
我们可以使用calendar模块的monthcalendar函数来生成当前月份的日历。
cal = calendar.monthcalendar(today.year, today.month)
2.4 打印日历
我们可以使用循环遍历生成的日历列表,并打印出每个日期。
```python for week in cal: for day in week: if day == 0: print(。
c语言基础代码编写的简单的万年历程序
#include<stdio.h>void print(int x,int y); //打印程序x表示这个月的总天数y表示这个月的1号的星期int month_day(int x,int y); //计算该月的天数x表示年份y表示月份int run(int y); //判断闰年y表示年份int month_cha(int x,int y); //每月一号的星期x表示年份y表示月份int year_cha(int x); //每年的一月一号的星期x表示年份void main(){int year,month,day,cha;char key='y';while(key=='y'){printf("请输入年月:");scanf("%d%d",&year,&month);day=month_day(year,month);cha=month_cha(year,month);print(day,cha);printf("是否继续输入(y/n):");scanf("%c",&key);scanf("%c",&key);}}void print(int x,int y){int i,j;printf("Sun Mon Tue Wed Thu Fri Sat\n");for(i=0;i<y;i++) //打印空缺部分printf("\t");for(j=1;j<=x;j++,i++){printf("%d\t",j);if(i%7==6){printf("\n");}}printf("\n");}int run(int y){int r;if(y%4!=0)r=0;else if((y%100==0)&&(y%400)!=0)r=0;elser=1;return r;}int month_day(int x,int y){int day;switch(y){case 1: day=31; break;case 2: day=28+run(x); break;case 3: day=31; break;case 4: day=30; break;case 5: day=31; break;case 6: day=30; break;case 7: day=31; break;case 8: day=31; break;case 9: day=30; break;case 10: day=31; break;case 11: day=30; break;case 12: day=31; break;}return day;}int month_cha(int x,int y){int day;switch(y){case 1: day=0; break;case 2: day=3; break;case 3: day=3+run(x); break;case 4: day=6+run(x); break;case 5: day=1+run(x); break;case 6: day=4+run(x); break;case 7: day=6+run(x); break;case 8: day=2+run(x); break;case 9: day=5+run(x); break;case 10: day=0+run(x); break;case 11: day=3+run(x); break;case 12: day=5+run(x); break;}day+=year_cha(x);if(day<0){day=7-(-day)%7;}if(day>6){day=day%7;}return day;}int year_cha(int x){int i,day=0;if(x>2012)for(i=2012;i<x;i++){day+=run(i);day++;}else if(x<2012)for(i=x;i<2012;i++){day=day-run(i);day--;}else day=0;printf("day=%d\n",day);return day;}}。
纯js简单日历实现代码
纯js简单⽇历实现代码复制代码代码如下:<!doctype html><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">body,ul,li,h2,p{margin:0px;padding:0xp;}#div1{width:200px;height:200px;background:#ccc;}.calendar{width:240px;height:345px;background:#ccc;margin:auto;}.calendar ul{list-style:none;width:232px;height:260px;margin:0px;padding:0px;}.calendar ul li{width:45px;height:65px;background:#333;float:left;display:inline;margin-left:11px;margin-top:10px;border:1px solid #ccc;text-align:center;color:#FFF;}.calendar ul li:hover{border:1px solid #000;}.text{background:#F96;margin:10px;padding-bottom:10px;height:45px;}.text h2{display:inline;}.active{background:#FFF !important;color:#C03 !important;}</style><script type="text/javascript">/* window.onload=function(){var oBtn=document.getElementById('btn1');var oTxt=document.getElementById('txt1');var oDiv=document.getElementById('div1');oBtn.onclick=function(){oDiv.innerHTML=oTxt.value;}}*/window.onload=function(){var aLi= document.getElementsByTagName('li');var Otxt =document.getElementById('tab').getElementsByTagName('div')[0];var aDats =['元旦1⽉1⽇','2⽉14⽇情⼈节','3⽉3⽇全国爱⽿⽇','4⽉1⽇愚⼈节','5⽉1⽇国际劳动节','6⽉1⽇国际⼉童节','7⽉1⽇中国共产党诞⽣⽇','8⽉1⽇中国⼈民解放军建军节','9⽉10⽇中国教师节', '10⽉1⽇中华⼈民共和国国庆节','11⽉9⽇消防宣传⽇','12⽉3⽇世界残疾⼈⽇' ];var i=0;for(i=0;i<aLi.length;i++) //for循环历遍li元素{aLi[i].index=i;aLi[i].onmouseover =function() //添加⿏标指向事件{for(i=0;i<aLi.length;i++) //for循环历遍li元素去掉li样式{aLi[i].className ='';}this.className ='active'; //给当前标签添加active 样式Otxt.innerHTML ='<h2>'+(this.index+1)+'</h2>'+'⽉'+'<p>'+aDats[this.index]+'</p>'; }}};</script></head><body><div id="tab" class="calendar"><ul><li class="active"><h2>1</h2><p>JAN</p></li> <li><h2>2</h2><p>FER</p></li><li><h2>3</h2><p>MAR</p></li><li><h2>4</h2><p>APR</p></li><li><h2>5</h2><p>MAY</p></li><li><h2>6</h2><p>JUM</p></li><li><h2>7</h2><p>JUL</p></li><li><h2>8</h2><p>AUG</p></li><li><h2>9</h2><p>SEP</p></li><li><h2>10</h2><p>OCT</p></li><li><h2>11</h2><p>NOV</p></li><li><h2>12</h2><p>DEC</p></li></ul><div class="text"></div></div></body></html>效果预览:。
万年历c语言编程代码
#include <stdio.h>// 函数声明int is_leap_year(int year);int get_first_day_of_year(int year);// 主函数int main() {int year, month, first_day_of_year, first_day_of_month, days_in_month;int i, j, k;printf("请输入年份(例如:2022):");scanf("%d", &year);first_day_of_year = get_first_day_of_year(year);for (month = 1; month <= 12; month++) {printf("%d 年%d 月\n", year, month);printf("日一二三四五六\n");if (month == 2) {if (is_leap_year(year)) {days_in_month = 29;} else {days_in_month = 28;}} else if (month == 4 || month == 6 || month == 9 || month == 11) { days_in_month = 30;} else {days_in_month = 31;}first_day_of_month = (first_day_of_year + (month-1)*28)%7;for (i = 1; i <= first_day_of_month; i++) {printf(" ");}for (j = 1; j <= days_in_month; j++) {printf("%2d ", j);k = (i + j - 1) % 7;if (k == 0) {printf("\n");}}printf("\n");}}// 判断是否闰年int is_leap_year(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);}// 计算年份第一天是星期几int get_first_day_of_year(int year) {int first_day = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;first_day = (first_day + 1) % 7;return first_day;}这是一个简单的万年历示例代码,但它不是完整的代码。
php简单的日历程序代码
php简单的日历程序代码PHP提供了date()函数,该函数提供了丰富的日期处理功能。
现在需要获得的数据有两个,第一个是当月的总天数;第二个是该月的第一天所在星期中的第几天,数字表示0(表示星期天)到6(表示星期六)。
通过date()函数可以很容易获得上面的数据代码如下复制代码<?php$month = $_GET['m']?$_GET['m']:date(…n‟);$year = $_GET['y']?$_GET['y']:date(…Y‟);$start_week = date(…w‟,mktime(0,0,0,$month,1,$year));$day_num = date(…t‟,mktime(0,0,0,$month,1,$year));$end = false;?><table><tr><td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr><tr><?phpfor($i = 0; $i<$start_week; $i++){ech o “<td></td>”;}$j=1;while($j<=$day_num){echo “<td>$j</td>”;$week = ($start_week+$j-1)%7;if($week ==6){echo “nt</tr>n”;if($j != $day_num)echo “t<tr>ntt”;else $end = true;}$j++;}while($week%7 != 6){echo “<td></td>”;$week++;}if(!$end)echo “n</tr>”;?></table>高级一点类代码如下复制代码<?phpclass Calendar{private $year;private $month;private $weeks = array('日','一','二','三','四','五','六');function __construct($options = array()) {$this->year = date('Y');$this->month = date('m');$vars = get_class_vars(get_class($this));foreach ($options as $key=>$value) {if (array_key_exists($key, $vars)) {$this->$key = $value;}}}function display(){echo '<table class="calendar">';$this->showChangeDate();$this->showWeeks();$this->showDays($this->year,$this->month);echo '</table>';}private function showWeeks(){echo '<tr>';foreach($this->weeks as $title){echo '<th>'.$title.'</th>';}echo '</tr>';}private function showDays($year, $month){$firstDay = mktime(0, 0, 0, $month, 1, $year);$starDay = date('w', $firstDay);$days = date('t', $firstDay);echo '<tr>';for ($i=0; $i<$starDay; $i++) {echo '<td> </td>';}for ($j=1; $j<=$days; $j++) {$i++;if ($j == date('d')) {echo '<td class="today">'.$j.'</td>';} else {echo '<td>'.$j.'</td>';}if ($i % 7 == 0) {echo '</tr><tr>';}}echo '</tr>';}private function showChangeDate(){$url = basename($_SERVER['PHP_SELF']);echo '<tr>';echo '<td><a href="?'.$this->preYearUrl($this->year,$this->month).'">'.'<<'.'</a></td>';echo '<td><a href="?'.$this->preMonthUrl($this->year,$this->month).'">'.'<'.'</a></td>';echo '<td n="3"><form>';echo '<select name="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';for($ye=1970; $ye<=2038; $ye++) {$selected = ($ye == $this->year) ? 'selected' : '';echo '<option '.$selected.' value="'.$ye.'">'.$ye.'</option>';}echo '</select>';echo '<select name="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value+''">';for($mo=1; $mo<=12; $mo++) {$selected = ($mo == $this->month) ? 'selected' : '';echo '<option '.$selected.' value="'.$mo.'">'.$mo.'</option>';}echo '</select>';echo '</form></td>';echo '<td><a href="?'.$this->nextMonthUrl($this->year,$this->month).'">'.'>'.'</a></td>';echo '<td><a href="?'.$this->nextYearUrl($this->year,$this->month).'">'.'>>'.'</a></td>';echo '</tr>';}private function preYearUrl($year,$month){$year = ($this->year <= 1970) ? 1970 : $year - 1 ;return 'year='.$year.'&month='.$month;}private function nextYearUrl($year,$month){$year = ($year >= 2038)? 2038 : $year + 1;return 'year='.$year.'&month='.$month;}private function preMonthUrl($year,$month){if ($month == 1) {$month = 12;$year = ($year <= 1970) ? 1970 : $year - 1 ;} else {$month--;}return 'year='.$year.'&month='.$month;}private function nextMonthUrl($year,$month){if ($month == 12) {$month = 1;$year = ($year >= 2038) ? 2038 : $year + 1;}else{$month++;}return 'year='.$year.'&month='.$month;}}调用方法代码如下复制代码<?php$params = array();if (isset($_GET['year']) && isset($_GET['month'])) {$params = array('year' => $_GET['year'],'month' => $_GET['month'],);}$params['url'] = 'demo.php';require_once 'calendar.class.php';?><html><head><title>日历demo</title><meta http-equiv="Content-Type" content="text/html" charset="UTF-8" /><style type="text/css">table.calendar {border: 1px solid #050;}.calendar th, .calendar td {width:30px;text-align:center;}.calendar th {background-color:#050;color:#fff;}.today{color:#fff;background-color:#050;}</style></head><body><div style="align:center"><?php$cal = new Calendar($params);$cal->display();?></div></body></html>。
数字万年历简易C语言程序源代码
数字万年历简易C语言程序源代码#include"reg52.h"#define uchar unsigned char#define uint unsigned intsbit rs=P2^0; // lcd 控制端sbit en=P2^2; // lcd 控制端sbit all=P2^1; // lcd 控制端sbit s0=P1^5; //时间调节sbit s1=P1^6;sbit s2=P1^7;sbit voice=P2^7;int nt;sbit DQ=P2^6;sbit DS1302_CLK = P2^3; //实时时钟时钟线引脚sbit DS1302_IO = P2^4; //实时时钟数据线引脚sbit DS1302_RST = P2^5; //实时时钟复位线引脚sbit ACC0 = ACC^0;sbit ACC7 = ACC^7;unsigned char time;#define ads_y 0#define ads_mo 3#define ads_d 6#define ads_w 9#define ads_h 65#define ads_m 68#define ads_s 71#define DS1302_SECOND 0x80 //写入ds地址宏定义#define DS1302_MINUTE 0x82#define DS1302_HOUR 0x84#define DS1302_WEEK 0x8A#define DS1302_DAY0x86#define DS1302_MONTH 0x88#define DS1302_YEAR 0x8Cvoid delay1(unsigned int i) //ds 延时函数放在前边是为了让EP 两次存储之间延时可以调用{while(i--);}void init_ds() //ds 初始化函数{unsigned char x=0;DQ=1; //DQ复位delay1(8); //稍做延时DQ=0; //单片机将DQ拉低delay1(80); //精确延时大于480usDQ=1; //拉高总线delay1(10);x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败delay1(5);}unsigned char read_ds() ///ds 读一个字节{unsigned char i=0;unsigned char dat=0;for(i=8;i>0;i--){DQ=0; // 给脉冲信号dat>>=1;DQ=1; // 给脉冲信号if(DQ)dat|=0x80;delay1(5);}return(dat);}void write_ds(unsigned char dat) ///写一个字节{unsigned char i=0;for(i=8;i>0;i--){DQ=0;DQ=dat&0x01;delay1(5);DQ=1;dat>>=1;}delay1(5);}void get_nt() //获取温度{unsigned char a=0;unsigned char b=0;init_ds();write_ds(0xCC); // 跳过读序号列号的操作write_ds(0x44); // 启动温度转换delay1(10);init_ds();write_ds(0xCC); //跳过读序号列号的操作write_ds(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度a=read_ds();b=read_ds();nt=0;nt=nt+b;nt=nt<<8;nt=nt+a;nt=nt*0.625; //此ds18b20 最低位为0.5 扩大十倍}void delay_1302(uint n) //按键长延时{while(n--);}void delay(uchar n) //lcd 延时子程序{uchar i,j;for(i=0;i<n;i++)< bdsfid="161" p=""></n;i++)<>for(j=0;j<10;j++);}void write_com(char com) //lcd comond in LCD控制字写入函数{en=0;P3=com;rs=0;delay(1);en=1;delay(2);en=0;delay(2);}void write_byte(char byte) //lcd data in LCD数据写入函数{en=0;P3=byte;rs=1;delay(1);en=1;delay(2);en=0;delay(2);}void init_lcd_com() //lcd init LCD初始化{all=0;write_com(0x38);write_com(0x0c);write_com(0x06);}void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数){unsigned char i;ACC = d;for(i=8; i>0; i--){DS1302_IO = ACC0; //相当于汇编中的RRCDS1302_CLK = 1;DS1302_CLK = 0;ACC = ACC >> 1;}}unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数){unsigned char i;for(i=8; i>0; i--){ACC = ACC >>1; //相当于汇编中的RRCACC7 = DS1302_IO;DS1302_CLK = 1;DS1302_CLK = 0;}return(ACC);}void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr); // 地址,命令DS1302InputByte(ucDa); // 写1Byte数据DS1302_CLK = 1;DS1302_RST = 0;}unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据{unsigned char ucData;DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr|0x01); // 地址,命令ucData = DS1302OutputByte(); // 读1Byte数据DS1302_CLK = 1;DS1302_RST = 0;return(ucData);}void DS1302_SetProtect(bit flag) //是否写保护{if(flag)Write1302(0x8E,0x10);elseWrite1302(0x8E,0x00);}void DS1302_SetTime(unsigned char Address, unsigned char V alue) // 关键函数向内写入时间{DS1302_SetProtect(0);Write1302(Address, ((V alue/10)<<4 | (V alue%10)));}void DS1302_GetTime(unsigned char xy) //关键函数向外读出时间{unsigned char ReadV alue;ReadV alue = Read1302(xy);time=((ReadV alue&0x70)>>4)*10+(ReadV alue&0x0F);}void display_nt(char ads,uchar t) //将读出时间显示char ge,shi;write_com(0x80+ads);shi=t%100/10;ge=t%10;write_byte(shi+'0');write_byte(ge+'0');}void display_nt2(char ads,uchar t) //将读出星期显示{ write_com(0x80+ads);write_byte(t+'0');}void get_dis() //获得时间并显示{DS1302_GetTime(DS1302_YEAR);display_nt(ads_y,time);DS1302_GetTime(DS1302_MONTH);display_nt(ads_mo,time);DS1302_GetTime(DS1302_DAY);display_nt(ads_d,time);DS1302_GetTime(DS1302_WEEK);display_nt2(ads_w,time);DS1302_GetTime(DS1302_HOUR);display_nt(ads_h,time);DS1302_GetTime(DS1302_MINUTE);display_nt(ads_m,time);DS1302_GetTime(DS1302_SECOND);display_nt(ads_s,time);}void set_time() //三按键设置时间{if(s0==0){write_com(0x0f); //开闪烁write_com(0x80+ads_m+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MINUTE); time++;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MINUTE); time--;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}}write_com(0x80+ads_h+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_HOUR); time++;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_HOUR); time--;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}}write_com(0x80+ads_w);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_WEEK); time++;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_WEEK); time--;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}}write_com(0x80+ads_d+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_DAY);time++;DS1302_SetTime(DS1302_DAY,time); display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_DAY);time--;DS1302_SetTime(DS1302_DAY,time);display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}}write_com(0x80+ads_mo+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MONTH); time++;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MONTH); time--;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}}write_com(0x80+ads_y+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_YEAR); time++;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_YEAR); time--;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}}write_com(0x0c);while(s0==0);delay_1302(30000);}}void init_lcd_dis() //显示初始化{write_com(0x80+2);write_byte('*');write_com(0x80+5);write_byte('*');write_com(0x80+8);write_byte('-');write_com(0x80+67);write_byte(':');write_com(0x80+70);write_byte(':');}void my() //右下角显示函数{char *pp;char i;code char p[]=" hou fei see a girl and say I LOVE YOU replay I LOVE YOU too ";pp=p;if(time<=60){write_com(0x80+74);for(i=0;i<=5;i++){write_byte(*(pp+time));pp++;}}}void display_nntt(int t) //当前温度显示{char ge,shi,bai;if(t<0){write_com(0x80+11);write_byte('-');t=-t;}else{write_com(0x80+11);write_byte('+');}bai=t/100;shi=t%100/10;ge=t%10;write_byte(bai+'0');write_byte(shi+'0');write_byte('.');write_byte(ge+'0');}void main(){init_lcd_com();init_lcd_dis();DS1302_SetTime(DS1302_SECOND,00); while(1){get_dis();set_time();get_nt();display_nntt(nt); my();}}。
C语言实现简单万年历
C语⾔实现简单万年历本⽂实例为⼤家分享了C语⾔实现简单万年历的具体代码,供⼤家参考,具体内容如下1234567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56#include <stdio.h>#include<stdlib.h>int year, month;int run[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };int ping[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };char week[7][10] = { "SUN","MON","TUE","WED","THU","FRI","SAT"}; bool IsLeap(int year){if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) //判断闰年 {return true;}else{return false;}}void PrintStar(){printf("\t\t\t万年历\t\t\t\n");printf("****************************************************\n");for(int i = 0; i < 7; i++){printf("%s\t", week[i]);}printf("\n");}int DaySum(int year, int month){int sum = 0;for(int i = 1990; i < year; i++){if(IsLeap(i)){sum += 366;}else{sum += 365;}}for(int i = 0; i < month - 1; i++){if(IsLeap(year)){sum += run[i];}else{sum += ping[i];}}return sum;}57585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104void PrintCal(int sum, int year, int month){int nRes, nTmp;nRes = sum % 7+1;//前⾯空⼏格nTmp = 7 - nRes;//从第⼏格开始打印 for (int i = 0; i < nRes; i++) { printf("\t");}if (IsLeap(year)){for (int i = 1; i < run[month - 1]+1; i++){ printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n");}} printf("\n"); } else{for (int i = 1; i < ping[month - 1]+1; i++){ printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n");}}printf("\n"); } }int main(void){while (1){scanf_s("%d %d", &year, &month); PrintStar(); PrintCal(DaySum(year, month), year, month); printf("****************************************************\n"); }return 0;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
c语言实现一个简单日历
c语⾔实现⼀个简单⽇历满⾜三个需求:1.输⼊⼀个年份,输出是在屏幕上显⽰该年的⽇历。
假定输⼊的年份在1940-2040年之间。
2.输⼊年⽉,输出该⽉的⽇历。
3.输⼊年⽉⽇,输出距今天还有多少天,星期⼏,是否是公历节⽇。
最终完善版代码:复制代码代码如下:#include<stdio.h>#include <string.h>#include <time.h>#include <math.h>#include <windows.h>int year , month , day ;int day_of_month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};//char wek[7]={'周⽇','周⼀','周⼆','周三','周四','周五','周六'};int current_year,current_month,current_day;/************************************通⽤关键函数**************************************************/ void cls_screen(){printf("请按任意键返回!\n");getchar();getchar();system("cls");}void get_current_time() //获取当前时间{time_t timep;struct tm *p;time(&timep);p = gmtime(&timep);current_year=1900+p->tm_year;current_month=1+p->tm_mon;current_day=p->tm_mday;}int judgement (int y){if (y % 400 == 0 || (y % 100 !=0 && y %4 ==0))return 1 ;else return 0 ;}int show_week (int year , int month , int day){/*公式:w=(y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1)%7*/int w ,k; //记录周⼏int year_last=year %100,c=year/100 , m = month;if (month==1 ){year_last-=1 ;m=13 ;}else if (month==2){year_last-=1;m=14;}w = (year_last + year_last/4 + c/4 - 2*c +26*(m+1)/10+day-1); // abs 绝对值if (w<0){k=(w%7+7)%7;}else k=w%7;return k ;}/************************************第⼀部分**************************************************/void print_year (int year){int i , k ,x ,first_week;printf ("请输⼊想要查询的年⽉(格式如2012):");scanf ("%d",&year);printf("=======================%d年===========================\n",year);printf("\n");if (judgement(year)){day_of_month[1]=29;}else day_of_month[1]=28;for (i=1 ; i <13 ; i++){first_week = show_week(year,i,1);printf("=====================%d⽉⽇历如下========================\n",i); printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");for (x=1;x<=first_week;x++){printf("\t");if (x%7==0) printf ("\n");}for (k=1;k<=day_of_month[i-1];k++){printf("%d\t",k);if (x%7==0) printf ("\n");x++;}printf("\n");printf("\n");printf("\n");}}/************************************第⼆部分**************************************************/void print_year_month (){int k ,x ,first_week;printf ("请输⼊想要查询的年⽉(格式如2012 12):");do{scanf ("%d %d",&year,&month);if (month<1||month>12){printf("您输⼊的⽉份有误哦~请输⼊正确的⽉份\n");printf ("请输⼊想要查询的年⽉(格式如2012 12):");}}while(1>month||month>12);printf("=====================%d年%d⽉======================\n",year,month); if (judgement(year)){day_of_month[1]=29;}else day_of_month[1]=28;first_week = show_week(year,month,1);printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");for (x=1;x<=first_week;x++){printf("\t");if (x%7==0) printf ("\n");}for (k=1;k<=day_of_month[month-1];k++){printf("%d\t",k);if (x%7==0) printf ("\n");x++;}printf("\n");}/************************************第三部分**************************************************/int year_before_sumdays (int year,int month, int day){int days=0 ,i,judgement1;int temp_day=0 ,sum_days; ////printf ("%d,%d\n",current_year,current_month);judgement1=judgement(year);/*===================⽐当前少=====================*/if (year < current_year ){for (i = year+1;i < current_year ;i++){if (judgement(i)){days=days+356;}else days+=355;}for (i = month+1;i<=12;i++){days=days+day_of_month[i-1];}days = days + day_of_month[month-1]-day; //指定⽇⼦距离当年结束还有多少天 //printf("去年还有%d\n",days);for (i = 0;i < current_month-1;i++ ){if (judgement1){day_of_month[1]=29;}temp_day = temp_day + day_of_month[i];}//当前⽇⼦是这⼀年的多少天temp_day = temp_day + current_day;//printf("今天是第%d天\n",temp_day);sum_days=temp_day + days ;}/*===================⽐当前多=====================*/if (year > current_year ){for (i =current_year+1;i < current_year ;i++){if (judgement(i)){days=days+356;}else days+=355;}for (i = current_month+1;i<=12;i++){days=days+day_of_month[i-1];}days = days + day_of_month[month-1]-current_day; //指定⽇⼦距离当年结束还有多少天 //printf("去年还有%d\n",days);for (i = 0;i <month-1;i++ ){if (judgement1){day_of_month[1]=29;}temp_day = temp_day + day_of_month[i];}//当前⽇⼦是这⼀年的多少天temp_day = temp_day + day;//printf("今天是第%d天\n",temp_day);sum_days=temp_day + days ;}/*===================⽐当前⼀样=====================*/if (year == current_year ){if(month <current_month){for (i=month+1;i<current_month;i++){if (judgement1){day_of_month[1]=29;}days = days + day_of_month[i];}sum_days = days + current_day + day_of_month[month-1] - day ;}if (month>current_month){for (i=current_month+1;i<month;i++){if (judgement1){day_of_month[1]=29;}days = days + day_of_month[i];}sum_days = days + day + day_of_month[month-1] - current_day ;printf("%d\n",days);}if (month==current_month){sum_days= abs(day-current_day);}}return sum_days ;}void print(int year,int month,int day){int week;printf ("请输⼊想要查询的年⽉(格式如2012 12 12 ):");do{scanf ("%d %d %d",&year,&month,&day);if (judgement(year)){day_of_month[1]=29;}printf("\n");if (day<=0 || day >day_of_month[month-1])printf ("%d⽉没有%d,请重新输⼊(格式如2012 12 12 ):",month,day);}while(day<=0 || day >day_of_month[month-1]);week=show_week (year,month ,day);printf("\n");switch(month)//判断查找天是否阳历节⽇先由⽉份判断是否有节⽇的⽉份再由⽇判断是否为节⽇ {case 1:switch(day){case 1:printf("元旦") ;break;default:printf("不是阳历节⽇");}break;case 2:switch(day){case 14:printf("情⼈节(Valentines Day)");break;default:printf("不是阳历节⽇");}break;case 3:switch(day){case 8:printf("妇⼥节¨(Women's Day)");break;case 12:printf("植树节(Arbor Day)");break;default:printf("不是阳历节⽇");}break;case 4:switch(day){case 1:printf("愚⼈节(April Fools Day)");break;case 5:printf("清明节(Tomb-sweeping Day)");break;default:printf("不是阳历节⽇");}break;case 5:switch(day){case 1:printf("劳动节(Labor Day)");break;case 4:printf("中国青年节(Chinese Youth Day)");default:printf("不是阳历节⽇");}break;case 6:switch(day){case 1:printf("⼉童节(Children's Day)");break;default:printf("不是阳历节⽇");}break;case 8:switch(day){case 1:printf("建军节(the Army's Day)");break;default:printf("不是阳历节⽇");}break;case 9:switch(day){case 10:printf("教师节(Teacher's Day)");break;default:printf("不是阳历节⽇");}break;case 10:switch(day){case 1:printf("国庆节(National Day)");break;case 31:printf("万圣节(Helloween Day)");break;default:printf("不是阳历节⽇");}break;case 12:switch(day){case 25 :printf("圣诞节(Christmas Day)");break;default:printf("不是阳历节⽇");}break;}printf("\n");printf("%d年%d⽉%d号是:",year,month,day);switch(week)//判断所查找天是星期⼏{case 0:printf("Sunday");break;case 1:printf("Monday");break;case 2:printf("Tuesday");break;case 3:printf("Wednesday");;break;case 4:printf("Thursday");break;case 5:printf("Friday");break;case 6:printf("Saturday");break;}printf("\n");printf("距离今天有%d天\n",year_before_sumdays ( year, month, day));printf("\n");}/********************************************************************************************/void main (){int choice,year,month,day,flag=1;char c , k;for(;1;)//显⽰程序菜单,为永真,每次查找完回到程序菜单ì{printf("===================================菜单选项===================================\n"); printf("请选择:\n");printf("* * * * * * * * 1.查找某⼀年的年历 * * * * * * * *\n");printf("* * * * * * * * 2.查找某⼀⽉的⽉历 * * * * * * * *\n");printf("* * * * * * * * 3.查找某⼀天 * * * * * * * *\n");printf("* * * * * * * * 0.退出 * * * * * * * *\n");printf("==============================================================================\n"); printf("请输⼊您的选择: ");do{if (flag){c=getche();printf("\n");printf("确定选择%c吗? (y/Y )或者(n/N): ",c);}if (flag ){k=getche();// printf("\n");}if (k == 'y' || k == 'Y'){printf("\n");if (c=='\n'){printf("\n");printf("输⼊有误,请输⼊数字\n");printf("\n");printf("请输⼊您的选择: ");}else if (!isdigit(c)){printf("\n");printf("输⼊有误,请输⼊数字\n");printf("\n");printf("请输⼊您的选择: ");}else if (isdigit(c)){choice = c-'0' ;if (choice < 0 || choice > 3 ){printf("输⼊有误,请输⼊0-3之间的数字\n"); }else break ;}}else if (k=='n' || k=='N'){printf("\n");printf("你选择了否,请重新输⼊选项: ");flag=1;}if ((k != 'y'&& k!='Y'&& k!= 'n'&& k!='N')){printf("\n");printf("请输⼊y/n: ");flag=0;if (flag == 0){k=getche();printf("\n");//getchar();}}}while(1);if (choice==1){print_year(year);cls_screen();}else if (choice==2){print_year_month ();cls_screen();}else if (choice==3){get_current_time();print(year,month,day);cls_screen();}else if (choice==0)break;else{printf ("您的输⼊有误,请重新输⼊\n");}}}以上就是本⽂所述的全部内容了,希望⼤家能够喜欢。
万年历代码
monWeeks[January] = yDay;
monWeeks[February] = ((monWeeks[January] +monLen[January] )%7);
monWeeks[Match] = ((monWeeks[February] +monLen[February] )%7);
printf("\n****************************************************\n");
printf(" 星期日 星期一 星期二 星期三 星期四 星期五 星期六\n");
//打印星期表头
for(i=0;i<FirstDay_Month;i++)
scanf("%d",&Year); //把输入的年份赋值给变量Year
printf("请输入月份<0~12>: "); //提示输入月份(1~12)
scanf("%d",&Month); //把输入的月份赋值给变量Month
y=Year;
FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几)
}
printf("\n-------------------------------------------------\n");
printf(" %d, %d \n",y,i);
printf("-------------------------------------------------\n");
简单的java万年历代码
private Calendar a; //日历功能
private GridLayout MyGridLayout = new GridLayout(2, 1, 0, 5); //设计容器
private JPanel row1 = new JPanel();
private JPanel row2 = new JPanel();
private JTextField JTMonth=new JTextField(10); //月份显示文本框
private JTextField JTYear=new JTextField(10); //年份显示文本框
private JButton JBAddYear=new JButton(">>"); //增加年份按钮
private JLabel[] numbers = new JLabel[42];
//private JLabel MyJLabel1=new JLabel("设计:王 时间:2014年12月");
private JLabel MyJLabel2=new JLabel("日 一 二 三 四 五 六");
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JFrame;
s = Integer.toString(MyYear); // 将年份转换为字符串类型
日历的制作代码
日历的制作代码<?php$year=@$_GET['year']; //获得地址栏的年份$month=@$_GET['month']; //获得地址栏的月份if(empty($year))$year=date("Y"); //初始化为本年度的年份if(empty($month))$month=date("n"); //初始化为本年度的月份$day=date("j"); //获取当天的天数$wd_ar=array("日","一","二","三","四","五","六"); //星期数组$wd=date("w",mktime(0,0,0,$month,1,$year)); //计算当月第一天是星期几//年链接$y_lnk1=$year<=1970?$year=1970:$year-1;$y_lnk2=$year>=2037?$year=2037:$year+1;//月链接$m_lnk1=$month<=1?$month=1:$month-1;$m_lnk2=$month>=12?$momth=12:$month+1;echo"<table cellpadding=6 cellspacing=0 width=200 bgcolor=#eeeeee><tr align=center bgcolor=#cccccc>";//输出年份。
单击“<”链接跳到上一年,单击“>”跳到下一年echo"<td colspan=4><a href='key.php?year=$y_lnk1&month=$month'><</a>".$year."年<a href='key.php?year=$y_lnk2&month=$month'>></a><td>";//输出月份。
Python实现的简单万年历例子分享-电脑资料
Python实现的简单万年历例子分享-电脑资料复制代码代码如下:#!/usr/bin/env python2#-*- coding:utf-8 -*-__author__ = 'jalright'"""使用python实现万年历"""def is_leap_year(year):"""判断是否是闰年,返回boolean值"""if year/4==0 and year/400 !=0:return Trueelif year/100 == 0 and year/400 ==0 :return Trueelse:return Falsedef getMonthDays(year,month):"""获取指定年月的月份有多少天"""days = 31 #31天居多,设置为默认值if month == 2 : #2月份要判断是否是闰年if is_leap_year(year):days=29else:days=28;elif month in [4,6,9,11]: #判断小月,只有30天days=30return daysdef getTotalDays(year,month):"""获取1990-01-01离现在有多少天,1990-01-01是星期一,以这个为标准来判断星期"""totalDays=0for i in range(1990,year): #使用range来循环,算出多少年多少天if is_leap_year(i): #判断是否是闰年totalDays += 366else:totalDays += 365for i in range(1,month): #使用range循环,算出今年前面几个月过了多少天totalDays +=getMonthDays(year,i)return totalDaysif __name__ == '__main__':while True: #循环判断是否输入错误的格式print "××××××××××python实现万年历××××××××"year = raw_input("请输入年份(如:1990):")month = raw_input("请输入月份:如:1")try: #捕捉输入异常格式和月份的正确year = int(year)month = int(month)if month <1 or month >1: #判断月份是否输入错误,错误就重新开始循环print "年份或者月份输入错误,请重新输入!"continueexcept: #捕捉到转换成整型异常,输出提示,重新开始循环print "年份或者月份输入错误,请重新输入!"continuebreak #如果没有异常就跳出循环#if is_leap_year(year):# print "%s是润年"%year#else:# print "%s是平年"%year#print "%s月份总共有%s天!"%(month,getMonthDays(year,month))print "日\t一\t二\t三\t四\t五\t六"iCount = 0 #计数器来判断是否换行for i in range(getT otalDays(year,month)%7):print '\t', #输出空不换行iCount+=1for i in range(1,getMonthDays(year,month)):print i,print '\t',iCount +=1if iCount%7 == 0 : #计数器取余为0,换行print ''您可能感兴趣的文章:Python时间戳与时间字符串互相转换实例代码python中关于时间和日期函数的常用计算总结(time和datatime) Python 时间处理datetime实例QQ空间搜狐微博人人网开心网百度搜藏更多Tags:Python 万年历复制链接收藏本文打印本文关闭本文返回首页上一篇:python实现simhash算法实例下一篇:windows下wxPython开发环境安装与配置方法相关文章2013-01-01Python内置的字符串处理函数整理2014-05-05python应用程序在windows下不出现cmd窗口的办法2013-11-11python Django连接MySQL数据库做增删改查2008-09-09Python urlopen 使用小示例2014-02-02python基础教程之实现石头剪刀布游戏示例2014-03-03用Python和MD5实现网站挂马检测程序2014-05-05Python Web开发模板引擎优缺点总结2008-08-08Python备份Mysql脚本2013-11-11python读取Android permission文件2014-06-06python网络编程学习笔记(六):Web客户端访问文章评论最近更新python thread 并发且顺序运行示例Python continue语句用法实例python实现apahce网站日志分析示例分析python服务器拒绝服务攻击代码pyqt4教程之实现半透明的天气预报界面示例Python爬虫框架Scrapy安装使用步骤Python实现多线程下载文件的代码实例python读写文件操作示例程序python解析xml模块封装代码zbar解码二维码和条形码示例热点排行Python入门教程超详细1小时学会python 中文乱码问题深入分析比较详细Python正则表达式操作指Python字符串的encode与decode研Python open读写文件实现脚本Python enumerate遍历数组示例应Python 深入理解yieldPython+Django在windows下的开发python 文件和路径操作函数小结python 字符串split的用法分享。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Dim x As Variant, y As Variant, z As Integer, m As Boolean Private Sub Command1_Click()Text1.Text = ""Text3.Text = ""Text4.Text = ""Text1.Enabled = TrueText3.Enabled = TrueText4.Enabled = TrueText1.SetFocusEnd SubPrivate Sub Command2_Click()Text2.Text = DateSelect Case (Weekday(Date) - 1)Case 0Text2.Text = Text2.Text + " 星期日"Case 1Text2.Text = Text2.Text + " 星期一"Case 2Text2.Text = Text2.Text + " 星期二"Case 3Text2.Text = Text2.Text + " 星期三"Case 4Text2.Text = Text2.Text + " 星期四"Case 5Text2.Text = Text2.Text + " 星期五"Case 6Text2.Text = Text2.Text + " 星期六"End SelectText1.Text = ""Text3.Text = ""Text4.Text = ""Text1.Enabled = FalseText3.Enabled = FalseText4.Enabled = FalseEnd SubPrivate Sub Text1_Change()If Len(Text1.Text) = 4 ThenText3.SetFocusEnd IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase Asc("0") To Asc("9")Case ElseKeyAscii = 0End SelectEnd SubPrivate Sub Text2_GotFocus()Text2.Text = DateSelect Case (Weekday(Date) - 1)Case 0Text2.Text = Text2.Text + " 星期日"Case 1Text2.Text = Text2.Text + " 星期一"Case 2Text2.Text = Text2.Text + " 星期二"Case 3Text2.Text = Text2.Text + " 星期三"Case 4Text2.Text = Text2.Text + " 星期四"Case 5Text2.Text = Text2.Text + " 星期五"Case 6Text2.Text = Text2.Text + " 星期六"End SelectText1.Text = ""Text3.Text = ""Text4.Text = ""Text1.Enabled = FalseText3.Enabled = FalseText4.Enabled = FalseEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Select Case KeyAsciiCase 48 To 57Case ElseKeyAscii = 0End SelectEnd SubPrivate Sub Text3_Change()Dim c As Integerc = Val(Text3.Text)If c <= 12 And Len(Trim(Text3.Text)) = 2 ThenText4.SetFocusElseIf Val(Text3.Text) >= 13 ThenText2.Text = "没有这一个月份"Text3.Text = ""End IfEnd SubPrivate Sub Text3_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase 48 To 57Case ElseKeyAscii = 0End SelectEnd SubPrivate Sub Text4_Change()Select Case Text3.TextCase "01", "03", "05", "07", "08", "10", "12"If Val(Text4.Text) <= 31 And Len(Trim(Text4.Text)) = 2 Then x = DateSerial(Text1.Text, Text3.Text, Text4.Text)y = Weekday(x) - 1Select Case (y)Case 0Text2.Text = "星期日"Case 1Text2.Text = "星期一"Case 2Text2.Text = "星期二"Case 3Text2.Text = "星期三"Case 4Text2.Text = "星期四"Case 5Text2.Text = "星期五"Case 6Text2.Text = "星期六"End SelectElseIf Val(Text4.Text) >= 32 ThenText2.Text = "没有这一天"Text4.Text = ""End IfCase "04", "06", "09", "11"If Val(Text4.Text) <= 30 And Len(Text4.Text) = 2 Thenx = DateSerial(Text1.Text, Text3.Text, Text4.Text)y = Weekday(x) - 1Select Case (y)Case 0Text2.Text = "星期日"Case 1Text2.Text = "星期一"Case 2Text2.Text = "星期二"Case 3Text2.Text = "星期三"Case 4Text2.Text = "星期四"Case 5Text2.Text = "星期五"Case 6Text2.Text = "星期六"End SelectElseIf Val(Text4.Text) >= 31 ThenText2.Text = "没有这一天"Text4.Text = ""End IfCase "02"Dim t As Integert = Text1.TextIf t Mod 100 = 0 ThenIf t Mod 400 = 0 Thenm = TrueElse: m = FalseEnd IfElseIf t Mod 4 = 0 Thenm = TrueElse: m = FalseEnd IfIf m = 1 ThenIf Val(Text4.Text) <= 29 And Len(Text4.Text) = 2 Thenx = DateSerial(Text1.Text, Text3.Text, Text4.Text)y = Weekday(x) - 1Select Case (y)Case 0Text2.Text = "星期日"Case 1Text2.Text = "星期一"Case 2Text2.Text = "星期二"Case 3Text2.Text = "星期三"Case 4Text2.Text = "星期四"Case 5Text2.Text = "星期五"Case 6Text2.Text = "星期六"End SelectElseIf Val(Text4.Text) >= 30 ThenText2.Text = "没有这一天"Text4.Text = ""End IfElseIf Val(Text4.Text) <= 28 And Len(Text4.Text) = 2 Thenx = DateSerial(Text1.Text, Text3.Text, Text4.Text)y = Weekday(x) - 1Select Case (y)Case 0Text2.Text = "星期日"Case 1Text2.Text = "星期一"Case 2Text2.Text = "星期二"Case 3Text2.Text = "星期三"Case 4Text2.Text = "星期四"Case 5Text2.Text = "星期五"Case 6Text2.Text = "星期六"End SelectElseIf Val(Text4.Text) >= 29 ThenText2.Text = "没有这一天"Text4.Text = ""End IfEnd IfEnd SelectEnd Sub。