Calendar cal = Calendar.getInstance();
System.out.println("now:"+cal.getTime());
 
// Set date : 월은 0부터 시작된다
cal.set(year, month-1, day, hour, min, sec);

// Prev a year
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) -1);
System.out.println("prev a year:"+cal.getTime());
 
 
// Prev a month
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) -1);
System.out.println("prev a month:"+cal.getTime());
 
// Prev a week
cal.set(Calendar.HOUR, -1 * 24 * 7);
System.out.println("prev a week:"+cal.getTime());
 
// Prev a day
cal.set(Calendar.HOUR, -24);
System.out.println("prev a day:"+cal.getTime());

+ Recent posts