首页 > 代码库 > 日期转换
日期转换
printf("请输入查询方式\n"); printf("输入1:表示查询第几天(输入年月日)\n"); printf("输入2:表示查询具体的日期(输入年和天数)\n"); int n=2, year=2001,month=12,day=31,dayOfTheYear=4; int numOfMonth[12]={31,29,31,30,31,30,31,31,30,31,30,31}; int numOfMonth1[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //scanf("%d",&n); if (n==1) { printf("请输入年月日\n"); scanf("%d %d %d",&year,&month,&day); int a=0; if ([self isRN:year]) { for (int i=0; i<month-1; i++) { a+=numOfMonth[i]; } a+=day; } else { for (int i=0; i<month-1; i++) { a+=numOfMonth1[i]; } a+=day; } printf("%d年%d月%d日是这一年的第%d天",year,month,day,a); } else if(n==2) { //printf("请输入年和第几天"); // scanf("%d %d ",&year,&dayOfTheYear); if ([self isRN:year]) { int a=0; for (int i=0; i<12; i++) { if (dayOfTheYear<31) { printf("%d第%d天是这一年的1月%d日",year, dayOfTheYear,dayOfTheYear); break; } a+=numOfMonth[i]; if (dayOfTheYear>a&&dayOfTheYear<=(a+numOfMonth[i+1])) { printf("%d第%d天是这一年的%d月%d日",year, dayOfTheYear,i+2,(dayOfTheYear-a)); break; } } } else {int a=0; for (int i=0; i<12; i++) { if (dayOfTheYear<31) { printf("%d第%d天是这一年的1月%d日",year, dayOfTheYear,dayOfTheYear); break; } a+=numOfMonth1[i]; if (dayOfTheYear>a&&dayOfTheYear<=(a+numOfMonth1[i+1])) { printf("%d第%d天是这一年的%d月%d日",year, dayOfTheYear,i+2,(dayOfTheYear-a)); break; } } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。