This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Modeling Day of the Week Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Modeling Day of the Week" Watch "Modeling Day of the Week" New topic
Author

Modeling Day of the Week

Troy Harvey
Greenhorn

Joined: Mar 01, 2007
Posts: 6
I'm working with a database table for "Templates." Each "Template" record has a couple of "Day of the Week" fields. They are represented as numbers (1 = Sun, 2 = Mon, etc).

I want to display the day of the week in a friendly way on the front end (like "Tuesday"). How should I model "Day of the Week" in Java? I was looking at the Java Calendar class, but I can't think of a good way to use that. Should I just write my own WeekDay class that does the work?

Thanks!
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
Have another table in the database, like a master table which has the mapping of the number to the day like 1=Sunday, 2=Monday. Alternatively you could just create a static Hashmap to hold this values and use it your code. A better way to do would be to use either a database ot a poperties file for creating this hashmap so that you don't have to touch your code when you want the format to be changed.


Amit Tank
Linked In
 
Consider Paul's rocket mass heater.
 
subject: Modeling Day of the Week