• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert day of week  RSS feed

 
Michael Sampson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have other ways of doing this but I was trying not to clutter up code. I am looking for an elegant way to do this. I have a string "MON", which I would to become "Monday". Is there some already written static routine in java that can do this. I have looked at the Calendar class a bit but this is not what it is designed for. I am thinking I will just have to write my own class. Well there probably is a way to get it out of Calendar but it's probably some formatting trick. Any ideas?

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out DateFormat and its subclass SimpleDateFormat. In essence, you do the following:
- create a (Simple)DateFormat that will only use the day of week
- use its parse method to create a Date
- use its format method to turn it back into the week day String
In short code:
You'll have to experiment a bit with repeating the day of the week pattern symbol; if you repeat it enough it will work the way you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!