wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Can I get the date of a specific weekday with the weeknumber as attribute? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can I get the date of a specific weekday with the weeknumber as attribute?" Watch "Can I get the date of a specific weekday with the weeknumber as attribute?" New topic
Author

Can I get the date of a specific weekday with the weeknumber as attribute?

Alia Huss
Ranch Hand

Joined: Feb 13, 2009
Posts: 63
Hello!
I'm currently working on a webapp which is supposed to handle the booking of several conference rooms.
Right now I'm trying to make a class that can get all the days of a specific week, and set their dates.
In the end you should be able to ask for any given week a specific year, and get a list of the seven days and their dates.

The method I'm struggling with looks like this:




Here things go a bit pearshaped. Is there any way that I can get the dates for the weekdays of a specific week?
Let's say that the seven dates in week 5 are 26, 27, 28, 29, 30, 31, 1.
Is there any way for me to get them out so I can call day.setDate(someInt) on each day?
Or do you have any other suggestions for how I could make this work?

Appreciate it!
Regards
Alia
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Check out java.util.Calendar.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alia Huss
Ranch Hand

Joined: Feb 13, 2009
Posts: 63
I did, didn't help me out that much.
Or maybe I just don't get how it works.
I'd really love a method that looked something like this:



But looking through the methods provided in Calendar I can't find anything close to this, and I can't figure out how I could make one myself. Is it possible to make one yourself, you think?
Any tips on how I should use Calendar to make one?
Thanks again.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

If you use Calendar.SUNDAY until Calendar.SATURDAY for your weekdays, it's actually quite simple:

For instance, getDate(2009, 5, Calendar.TUESDAY) returns 27 - and in week 5 of 2009, January 27th was a Tuesday.
Alia Huss
Ranch Hand

Joined: Feb 13, 2009
Posts: 63
Wow! Thank you!
Now I finally have an idea about how to fix this.

Thank you!
 
 
subject: Can I get the date of a specific weekday with the weeknumber as attribute?