/**
* 算日期的
* @param type
* @return 相应区间段的起止日期
*/
private static String[] getDateDiff(String type){
String[] ret = new String[2];
SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
//周日算起,周三返回4
int day_of_week = c.get(c.DAY_OF_WEEK);
//正常算法,3号返回3
int day_of_month = c.get(c.DAY_OF_MONTH);
//从0算起,12月返回11
int month_of_year = c.get(c.MONTH);
//返回正常
int year = c.get(c.YEAR);
System.out.println(day_of_week+","+day_of_month+","+month_of_year+","+year);
if("week".equals(type)){
c.set(c.DATE, day_of_month-day_of_week-5);
ret[0] = sm.format(c.getTime());
c.add(c.DATE, 7);
ret[1] = sm.format(c.getTime());
}
if("month".equals(type)){
c.add(c.MONTH, -1);
c.set(c.DATE, 1);
ret[0] = sm.format(c.getTime());
c.add(c.MONTH, 1);
ret[1] = sm.format(c.getTime());
}
if("season".equals(type)){
int s_diff = month_of_year%3;
c.add(c.MONTH, s_diff==0?-3:-s_diff-3);
c.set(c.DATE, 1);
ret[0] = sm.format(c.getTime());
c.add(c.MONTH, 3);
ret[1] = sm.format(c.getTime());
}
if("year".equals(type)){
c.set(c.YEAR, year-1);
c.set(c.MONTH, 0);
c.set(c.DATE, 1);
ret[0] = sm.format(c.getTime());
c.add(c.MONTH, 12);
ret[1] = sm.format(c.getTime());
}
return ret;
}