zoukankan      html  css  js  c++  java
  • 20150910输入一个日期判断是这一年的第一天

    bool isok = false;//用来记录日期是否正确
    bool isrun = false;//用来判断是否是闰年

    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)
    {
    if (month == 2)
    {
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
    {
    if (day >= 1 && day <= 29)
    {
    isok = true;
    isrun = true;
    }
    else
    {
    Console.WriteLine("应在29天范围之内");
    }
    }
    else
    {
    if (day >= 1 && day <= 28)
    {
    isok = true;
    }
    else
    {
    Console.WriteLine("应在28天范围之内");
    }
    }
    }
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {
    if (day >= 1 && day <= 31)
    {
    isok = true;
    }
    else
    {
    Console.WriteLine("日期应在31天之内");
    }
    }

    if (month == 4 || month == 6 || month == 9 || month == 11)
    {
    if (day >= 1 && day <= 30)
    {
    isok = true;
    }
    else
    {
    Console.WriteLine("日期应在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();
    }

  • 相关阅读:
    TCP协议实现双工通信
    搭建本地FTP服务器
    CSS 3 选择器root、not、empty、target
    CSS 3 中的伪类选择器
    CSS 3 中的属性选择器
    Entity Framework Code First属性映射约定
    Entity Framework数据库初始化四种策略
    HTML 5 Base 64 编码
    HTML 5 离线程序
    HTML5 本地数据库IndexedDB数据库
  • 原文地址:https://www.cnblogs.com/hz1234/p/4799882.html
Copyright © 2011-2022 走看看