public static ArrayList getYearList() {
ArrayList list = new ArrayList();
Calendar c = null;
c = Calendar.getInstance();
c.setTime(new Date());
int currYear = Calendar.getInstance().get(Calendar.YEAR);
int startYear = currYear - 5;
int endYear = currYear + 10;
for (int i = startYear; i < endYear; i++) {
list.add(new Integer(i));
}
return list;
}
public static int getCurrYear() {
return Calendar.getInstance().get(Calendar.YEAR);
}
/**
* 得到某一年周的总数
*
* @param year
* @return
*/
public static LinkedHashMap getWeekList(int year) {
LinkedHashMap map = new LinkedHashMap();
Calendar c = new GregorianCalendar();
c.set(year, Calendar.DECEMBER, 31, 23, 59, 59);
int count = getWeekOfYear(c.getTime());
/**
* 得到一年的总周数
* @param year
* @return
*/
public static int getWeekCountInYear(int year){
Calendar c = new GregorianCalendar();
c.set(year, Calendar.DECEMBER, 31, 23, 59, 59);
int count = getWeekOfYear(c.getTime());
return count;
}
/**
* 取得当前日期是多少周
*
* @param date
* @return
*/
public static int getWeekOfYear(Date date) {
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setMinimalDaysInFirstWeek(7);
c.setTime(date);
return c.get(Calendar.WEEK_OF_YEAR);
}
/**
* 得到某年某周的第一天
*
* @param year
* @param week
* @return
*/
public static Date getFirstDayOfWeek(int year, int week) {
Calendar c = new GregorianCalendar();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DATE, 1);
Calendar cal = (GregorianCalendar) c.clone();
cal.add(Calendar.DATE, week * 7);
return getFirstDayOfWeek(cal.getTime());
}
/**
* 得到某年某周的最后一天
*
* @param year
* @param week
* @return
*/
public static Date getLastDayOfWeek(int year, int week) {
Calendar c = new GregorianCalendar();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DATE, 1);
Calendar cal = (GregorianCalendar) c.clone();
cal.add(Calendar.DATE, week * 7);
return getLastDayOfWeek(cal.getTime());
}
/**
* 得到某年某月的第一天
* @param year
* @param month
* @return
*/
public static Date getFirestDayOfMonth(int year,int month){
month = month-1;
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);