Archive for January, 2009

Add / Subtract Date using Calendar

January 7, 2009

Many methods of Date() class is deprecated and the replacement is Calendar class. The following example shows how to display last month’s date.

java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(“dd-MMMM-yyyy);
Calendar c1 = Calendar.getInstance();
c1.add(Calendar.MONTH,-1);
System.out.println(“Last Month Date : ” + dateFormat.format(c1.getTime()));

Advertisements

%d bloggers like this: