• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar roll() not working

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting a Calendar representing today - March 1st, 2001 and rolling it back one day. I am not ending up with Feb 28th, but March 31st. This has worked in changing from January to Fevruary, but now I am having this problem. I read in the API that GregorianCalendar should resolve this issue, but I saw the same results - March 31st, 2001.
Any thoughts on how to fix this? Besides writing code to handle February?
GregorianCalendar newCal = new GregorianCalendar();
System.out.println("Todays calendar date:" + getStringFromCalendar(newCal));
//roll back the number of days between the dates passed in
newCal.roll(Calendar.DATE, -1);
System.out.println("After rollback New calendar date:" + getStringFromCalendar(newCal));
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Johanna,
Try to use Calendar.DAY_OF_YEAR instead. It will work every time in the roll method.
NOTE: According to API: Calendar.DATE is equivalent to Calendar.DAY_OF_MONTH which makes sense with yours results!
Regards,
Manfred.
[This message has been edited by Manfred Leonhardt (edited March 01, 2001).]
 
Judy Herilla
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred, that did the trick!!!
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic