Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Java Calender  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing the logic around the java Calender. I have following requirements.

Working on day of week calender which contains 4 weeks in a month. Need to select Day of a week for a month. If selected week day is passed then for next month same week day has to be selected.
If a month start on Saturday then second Monday will be 10th of that month rather than 3rd.

Please let me know if there are any utility is available in java to achieve above or any sample code will be much appreciated.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Joda Time. It's a library providing much more functionality than the basic date time stuff in java. Not sure if your specific requirements are met, but it should help.
 
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

accnit Jai wrote: Working on day of week calender which contains 4 weeks in a month. Need to select Day of a week for a month. If selected week day is passed then for next month same week day has to be selected.
If a month start on Saturday then second Monday will be 10th of that month rather than 3rd.


I'm sorry but I'm not sure I understand what you mean by this.
I can tell you the Calendar class has methods to get and set this type of information (eg Day of week, Day of Month, Day of week in Month etc). Alternatively you can try Joda time which has lots of useful date handling features.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

accnit Jai wrote:Please let me know if there are any utility is available in java to achieve above or any sample code will be much appreciated.


Like the others, I'd suggest looking at Joda Time; but only AFTER you've worked out how to do it for yourself.

What you want is perfectly easily obtainable from the Java GregorianCalendar class because, like it or not, Calendar's DAY_OF_WEEK field is a number (from 1 for Sunday through 7 for Saturday). Combine that with DAY_OF_WEEK_IN_MONTH and you have a simple way of getting the correct day.

My question to you is: what do you do about getting the 5th X-day of a month? There are several months that have them.

Winston
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!