aspose file tools*
The moose likes Beginning Java and the fly likes calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calendar " Watch "calendar " New topic
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: 3646
    
  15
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calendar