首页 > 代码库 > 日期转换

日期转换

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;                }            }        }    }