• 0910 输入一个年月日,判断是否闰年,输入几月几日,输出是今年的第几天


                   

    Console.Write("输入年:");                

    int year = int.Parse(Console.ReadLine());

    Console.Write("输入月:");                

    int month = int.Parse(Console.ReadLine());                

    Console.Write("输入日:");                

    int day = int.Parse(Console.ReadLine());

                   

    bool isok = false;//用来记录日期是否正确                

    bool isrun = false;

                   

    if (year >= 1759 && year < 9999)                

    {                    

    if (month >= 1 && month <= 12)//日期大于等于1天 并且 小于等于12天                    

    {                        

    if (month == 2)//日期是二月                        

    {                            

    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))//输入的年份整数400 或者 整除4并且不被100整除                            

    {                                

    if (day >= 1 && day <= 29)//日期大于等于1天 并且 小于等于29天                                

    {                                    

    isok = true;                                    

    isrun = true;                                

    }                                

    else                                

    {                                    

    Console.WriteLine("应在29天范围之内"); //除此之外应该在29天范围以内                                

    }                            

    }                            

    else                            

    {                                

    if (day >= 1 && day <= 28) //日期大于等于1天 并且 小于等于28天                                

    {                                    

    isok = true;                                

    }                                

    else                                

    {                                    

    Console.WriteLine("应在28天范围之内"); //除此之外应该在28天范围以内

                                   

    }                            

    }                        

    }                        

    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)  //1 3 5 7 8 10 12月份                        

    {                            

    if (day >= 1 && day <= 31) //日期大于等于1天 并且 小于等于31天                            

    {                                

    isok = true;                            

    }                            

    else                            

    {                                

    Console.WriteLine("日期应在31天之内"); //除此之外应该在31天以内

                               

    }                        

    }

                           

    if (month == 4 || month == 6 || month == 9 || month == 11)  //4 6 9 11月份                        

    {                            

    if (day >= 1 && day <= 30)//日期小于等于1天 并且 大于等于31天                            

    {                                

    isok = true;                            

    }                            

    else                            

    {                                

    Console.WriteLine("日期应在30天之内"); //除此之外应该在30天以内                            

    }                        

    }                    

    }                    

    else                    

    {                        

    Console.WriteLine("月份不正确");                    

    }                

    }                

    else               

      {                    

    Console.WriteLine("年份不正确");                

    }

                   

    int sumday = 0;//第多少天                

    if (isok)//日期正确,计算天数                

    {                    

    if (isrun)//是闰年                    

    {                        

    if (month == 1)                        

    {                            

    sumday = day;                        

    }                        

    if (month == 2)                        

    {                            

    sumday = 31 + day;                        

    }                        

    if (month == 3)                        

    {                            

    sumday = 31 + 29 + day;                        

    }                        

    if (month == 4)                        

    {                            

    sumday = 31 + 29 + 31 + day;

                           

    }                         if (month == 5)                         {                             sumday = 31 + 29 + 31 + 30 + day;                         }                         if (month == 6)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + day;                         }                         if (month == 7)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + day;                         }                         if (month == 8)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;                         }                         if (month == 9)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;                         }                         if (month == 10)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;                         }                         if (month == 11)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;                         }                         if (month == 12)                         {                             sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;                         }                     }                     else                                                                    //又或者不是闰年                     {                         if (month == 1)                         {                             sumday = day;                         }                         if (month == 2)                         {                             sumday = 31 + day;                         }                         if (month == 3)                         {                             sumday = 31 + 28 + day;                         }                         if (month == 4)                         {                             sumday = 31 + 28 + 31 + day;                         }                         if (month == 5)                         {                             sumday = 31 + 28 + 31 + 30 + day;                         }                         if (month == 6)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + day;                         }                         if (month == 7)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + day;                         }                         if (month == 8)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;                         }                         if (month == 9)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;                         }                         if (month == 10)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;                         }                         if (month == 11)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;                         }                         if (month == 12)                         {                             sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;                         }                     }

                        Console.WriteLine("第{0}天", sumday);

                    }                 else                 {                     Console.WriteLine("已经日期不正确,算不出来!");                 }                                 Console.ReadLine();

  • 相关阅读:
    python 有关datetime时间日期 以及时间戳转换
    开园杂记
    vue beforeRouteEnter 注意点
    html 头像裁剪框
    window server服务器配置ftp服务
    js 使用 delete 删除对象的属性
    win 自带的截屏工具
    idea 配置新建类自动加注解
    mysql varchar 使用唯一索引时无法区分大小写 可以使用varbinary
    在 laradock 环境中使用 laravel-swoole 加速你的 laravel 应用
  • 原文地址:https://www.cnblogs.com/jlhea/p/4799914.html
Copyright © 2020-2023  润新知