| Author |
calendar
|
Manoj Raghuwanshi
Ranch Hand
Joined: Jun 20, 2004
Posts: 75
|
|
I am trying to print date :- Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, -1); System.out.println(cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, -1); System.out.println(cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, -1); System.out.println(cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, -1); System.out.println(cal.getTime()); it is giving output:- Tue Oct 30 02:17:20 PDT 2007 Sat Sep 29 02:17:20 PDT 2007 Thu Aug 30 02:17:20 PDT 2007 Mon Jul 30 02:17:20 PDT 2007 can any body please tell me what should be the code so that output will be:- Tue Oct 30 02:17:20 PDT 2007 Mon Oct 29 Sun Oct 28 Sat Oct 27
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
The Calendar.set() method sets a field. You are trying to set the day of the month to -1, which obviously produces an unexpected result. To decrement the day use Calendar.add(Calendar.DAY_OF_MONTH, -1). [ November 02, 2007: Message edited by: Joanne Neal ]
|
Joanne
|
 |
Manoj Raghuwanshi
Ranch Hand
Joined: Jun 20, 2004
Posts: 75
|
|
|
thanks
|
 |
 |
|
|
subject: calendar
|
|
|