/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package calendartest; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; /** * * @author jcmtiernan */ public class CalendarTest { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd HH:MM"); Calendar calendar = new GregorianCalendar(2013,0,8); System.out.println("Cal1 : " + sdf.format(calendar.getTime())); //add one month calendar.add(Calendar.MONTH, -1); System.out.println("Date : " + sdf.format(calendar.getTime())); calendar.add(Calendar.MINUTE, -3); System.out.println("Date : " + sdf.format(calendar.getTime())); //subtract 10 days calendar.add(Calendar.DAY_OF_MONTH, 32); System.out.println("Date : " + sdf.format(calendar.getTime())); Calendar calendar2 = new GregorianCalendar(2013,0,6); System.out.println("Cal2 : " + sdf.format(calendar2.getTime())); System.out.println("calendar is before calendar2 ? " + calendar.before(calendar2)); } }