该方法已经不记得出处地址了,但是确实是一个好方法。 /** * 根据传入的年份和月份获得该月份的天数 * * @param year * 年份-正整数 * @param month * 月份-正整数 * @return 返回天数 */ public int getDayNumber(int year, int month) { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (2 == month && 0 == (year % 4) && (0 != (year % 100) || 0 == (year % 400))) { days[1] = 29; } return (days[month - 1]); } JAVA判断当前日期是星期几 /** * 判断当前日期是星期几<br> * <br> * @param pTime 修要判断的时间<br> * @return dayForWeek 判断结果<br> * @Exception 发生异常<br> */ public static int dayForWeek(String pTime) throws Exception { format = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(format.parse(pTime)); int dayForWeek = 0; if(c.get(Calendar.DAY_OF_WEEK) == 1){ dayForWeek = 7; }else{ dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1; } return dayForWeek; }