Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Modeling Day of the Week  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!