首页 > 其他 > 详细

日期转换

时间:2014-07-22 22:47:02      阅读:314      评论:0      收藏:0      [点我收藏+]
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;
                }
            }
        }
    }

日期转换,布布扣,bubuko.com

日期转换

原文:http://www.cnblogs.com/lidongq/p/3859714.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!