计算输入日期的下一天的nextDate()

 

同样是软件测试课程的作业,测试过程不解释,贴图贴代码。

 

 

 

计算输入日期的下一天的nextDate()_第1张图片 

public static ArrayList NextDate(int nowYear, int nowMonth, int nowDay) { ArrayList arr = new ArrayList(); if (nowYear <= 3000 && nowYear >= 1000 && nowMonth <= 12 && nowMonth >= 1 && nowDay >= 1 && nowDay <= getDays(nowYear, nowMonth)) { int nextYear; int nextMonth; int nextDay; if (nowDay == getDays(nowYear, nowMonth)) { if (nowMonth == 12) { nextYear = nowYear + 1; nextMonth = 1; nextDay = 1; } else { nextYear = nowYear; nextMonth = nowMonth + 1; nextDay = 1; } } else { nextYear = nowYear; nextMonth = nowMonth; nextDay = nowDay + 1; } arr.Add(nextYear); arr.Add(nextMonth); arr.Add(nextDay); } else { arr.Add("错误年份"); arr.Add("错误月份"); arr.Add("错误天数"); } return arr; } protected static bool isRun(int year) { if (year % 4 == 0 && year % 400 != 0) { return true; } return false; } protected static int getDays(int year, int month) { int days = 0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: days = isRun(year) ? 29 : 28; break; case 4: case 6: case 9: case 11: days = 30; break; } return days; } 

你可能感兴趣的:(ASP.NET)