• 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 : getting week of month

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get the dates for a particular week in a month.
I am trying to use set(Calendar.WEEK_OF_MONTH) and it is giving me strange results. Here is the code:

The output is
Fri Mar 12 10:50:59 GMT+05:30 2004
As 1st March 2003 is a Monday, the next week date I am expecting is 8th march. Can anyone help?
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try change 'date.set(Calendar.WEEK_OF_MONTH, 2);' to: 'date.add(Calendar.WEEK_OF_MONTH, 1);' witch add one week to the current Date.
Ren�
 
Gouri Bargi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene. It works. Meanwhile, I came across another alternative - if I modify the code as following, it works:

And another alternative - If I add a call to
date.get(Calendar.WEEK_OF_MONTH) before setting the week of month, I get the desired output:

Is this a bug?
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try the "complete ()" method before using the values. From the api docco:


protected void complete();
Fills in any unset fields in the calendar fields. First, the computeTime() method is called if the time value (millisecond offset from the Epoch) has not been calculated from calendar field values. Then, the computeFields() method is called to calculate all calendar field values.


[ March 12, 2004: Message edited by: Eddie Vanda ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic