Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -); //得到前一天
calendar.add(Calendar.MONTH, -); //得到前一个月
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+;
注意月份加一 /**
* 判断当前日期是星期几<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 = ;
if(c.get(Calendar.DAY_OF_WEEK) == ){
dayForWeek = ;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - ;
}
return dayForWeek;
}