Android使用GridView实现日历功能(详细代码)(3)

import java.util.Calendar;

public class SpecialCalendar {

private int daysOfMonth = 0;      //某月的天数
 private int dayOfWeek = 0;        //具体某一天是星期几


 
 
 // 判断是否为闰年
 public boolean isLeapYear(int year) {
  if (year % 100 == 0 && year % 400 == 0) {
   return true;
  } else if (year % 100 != 0 && year % 4 == 0) {
   return true;
  }
  return false;
 }

//得到某月有多少天数
 public int getDaysOfMonth(boolean isLeapyear, int month) {
  switch (month) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   daysOfMonth = 31;
   break;
  case 4:
  case 6:
  case 9:
  case 11:
   daysOfMonth = 30;
   break;
  case 2:
   if (isLeapyear) {
    daysOfMonth = 29;
   } else {
    daysOfMonth = 28;
   }

}
  return daysOfMonth;
 }
 
 //指定某年中的某月的第一天是星期几
 public int getWeekdayOfMonth(int year, int month){
  Calendar cal = Calendar.getInstance();
  cal.set(year, month-1, 1);
  dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;
  return dayOfWeek;
 }
 
 
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/844032ee1788eea531d7a0d0708bd630.html