判断某年某月有几天

 Console.WriteLine("请输入年份:");
            try
            {
                int year = Convert.ToInt32(Console.ReadLine());//有可能抛异常
                Console.WriteLine("请输入月份:");
                try
                {
                    int month = Convert.ToInt32(Console.ReadLine());//1-12 //有可能抛异常
                    if (month >= 1 && month <= 12)
                    {
                        int day = 0;
                        switch (month)
                        {
                            case 1:
                            case 3:
                            case 5:
                            case 7:
                            case 8:
                            case 12:
                                day = 31;
                                break;

                            case 2:
                                //判断是否是闰年
                                if ((year % 4 == 0) || (year % 4 == 0 && year % 100 != 0))
                                {
                                    day = 29;
                                }
                                else
                                {
                                    day = 28;
                                }
                                break;

                            default:
                                day = 30;
                                break;
                        }
                        Console.WriteLine("{0}年{1}月有{2}天", year, month, day);

                    }//if判断的括号
                    else
                    {
                        Console.WriteLine("输入的月份不合要求");
                    }
                }//try月份的括号
                catch//跟月份配套
                {
                    Console.WriteLine("输入的月份有误");
                }
            }//try年份的括号
            catch //跟年份配套try
            {
                Console.WriteLine("输入的年份有误");
            }
            Console.ReadKey();
时间: 2024-08-11 06:10:32

判断某年某月有几天的相关文章

Js获取当前日期时间+日期印证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天

Js获取当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天 字符串转日期型+Js当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+日期所在年的第几周 日期时间脚本库方法列表Date.prototype.isLeapYear 判断闰年Date.prototype.Format 日期格式化Date.prototype.DateAdd 日期计算Date.prototype.DateDiff 比较日期差Date.prototype.toString 日期转字符

php判断某年某月有多少天

<?php function yearMonthDays($year,$month){ if (in_array($month, array(1, 3, 5, 7, 8, 01, 03, 05, 07, 08, 10, 12))) {   return '31';   }elseif ($month == 2){   if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) {        //判断是否是闰年  

SwitchDemo(1).java【输入年份和月份,判断某年某月有多少天】

//课堂习题:输入年份和月份,判断某年某月有多少天 import java.util.Scanner; public class SwitchDemo{ public static void main(String [] args){ Scanner input=new Scanner(System.in); System.out.print("请输入需要查询的年份:"); int year=input.nextInt(); System.out.print("请输入需要查询

判断某年某月的天数

1 #include<stdio.h> 2 #include<stdlib.h> 3 //判断指定的某年某月有多少天 4 void main() 5 { 6 int year,month; 7 int leap,days; 8 printf("please input a year ,month\n"); 9 scanf("%d-%d",&year,&month); 10 if((year%4==0)&&(ye

js判断某年某月有多少天

function getCountDays(ym) { var curDate = new Date(ym); /* 获取当前月份 */ var curMonth = curDate.getMonth(); /* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */ curDate.setMonth(curMonth + 1); /* 将日期设置为0 */ curDate.setDate(0); /* 返回当月的天数 */ return curDate.getDate();}

Java实验项目二——打印某年某月日历

Program:打印万年历(输入年份,月份,输出该月的日历,已知1900年1月1日是星期一), 要 求: (1)编写一个方法判断闰年: (2)编写一个方法判断某年某月有多少天: (3)编写一个方法计算某年某月前距离1900年1月1日的总天数:(4)编写一个输出某年某月日历的方法: (5)编写一个测试方法. Description:该项目由多个类实现,最后类为main方法的调用.代码如下: 1 /* 2 *Description:定义工具类 3 * 4 * */ 5 6 package tools

2.2打印日历实现输出某年某月

//打印日历实现输出某年某月 #include<iostream> #include<iomanip> #include<string> using namespace std; //判断平闰年 int doyear(int year) { if((year%4==0)&&(year%100!=0)||(year%400==0)) return 1; else return 0; } //判断某年的第一天是星期几 int doweek(int year)

某年某月的某一天

某年某月的某一天 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 58(31 users) Total Accepted: 32(26 users) Rating: Special Judge: No Description 因为大雄考了有史以来也是唯一一次的100分,叮当猫答应带大雄去未来看一看.但是笨蛋大雄把时光机的时间调错了,结果回到了古代.叮当猫的时光机是这么用的:输入一个数n,时光机就会去到n天后或者是n天前,然后选择是往

获取某年某月有多少天 &amp; 常用日期转换

1 private void Form1_Load(object sender, EventArgs e) 2 { 3 DateTime date=System.DateTime.Today;//只有日期 4 //System.DateTime.Now; //日期+时间 5 int year= date.Year; 6 int month=date.Month; 7 8 int daysNum=System.DateTime.DaysInMonth(year,month);//返回某年某月有多少