• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java DateFormatSymbols using getWeekdays() method shows Text version of day of week

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a follow up post to my other post about the Calendar Class ENUM DayOfWeek question.

***My question would be to ask for feedback from the moderators regarding the value of this class and method in creating calendar related applications***

This is new information and solves (for me) the purpose of outputting the TEXT form of the days of the week using the class DateFormatSymbols, and
the getWeekdays() method in addition to a for loop. Code example at the end of this post.

Per http://docs.oracle.com/javase/7/docs/api/java/text/DateFormatSymbols.html,
"DateFormatSymbols is a public class for encapsulating localizable date-time formatting data, such as the names of the months, the names of the days of the week, and the time zone data. DateFormat and SimpleDateFormat both use DateFormatSymbols to encapsulate this information."

Per http://devmanuals.com/tutorials/java/corejava/DateTimes/DateFormatSymbolsgetWeekdays.html,
"The getWeekdays() method returns a string array of each weekdays' name."

The thing to note is that the CONSTANT FIELD VALUES for the days of the week start with SUNDAY = 1 thru SATURDAY = 7. There is no 0th value.
The String array that holds the text version of the days of the week does have a 0th element, however, it is empty.
Thus, the for loop should start with -1- to begin with SUNDAY.
Here is the code per the link above:



Output is:
Full name of day : Sunday
Full name of day : Monday
Full name of day : Tuesday
Full name of day : Wednesday
Full name of day : Thursday
Full name of day : Friday
Full name of day : Saturday

------------------------------------------------------------

For me, this brings the process of using the Calendar and Date classes along with the related classes for formatting the output of the fields full circle.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberta Fine wrote:Thus, the for loop should start with -1- to begin with SUNDAY.


Not necessarily. What about simply:

For me, this brings the process of using the Calendar and Date classes along with the related classes for formatting the output of the fields full circle.


I suspect it may have something to do with the flak they got for making Calendar.MONTH 0-based, which causes no end of mistakes. Far better, I reckon, to have a wasted array element than force everyone to use a convention they don't use anywhere else (although I'd also say that it's much less important with day numbers than it is with months).

My 2¢

Winston
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roberta

There have been a number of problems over the years using Calendar and Date. Hence, why developers look for other options like Joda Time and DateUtils. I would be surprised to find a junior Java developer that didn't fall into one of the many pitfalls with these classes.

Personally, I am looking forward to getting to grips with Java 8 Date and Time APIs.
 
Roberta Fine
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bartenders,

Thank you for the feedback. I like the alternate loop method Winston, I'll keep that in my toolkit.
And James as for Joda-Time and DateUtils classes, I'll look into those next and see how they compare.
As it turns out, because of both the simplicity and complexity (including pitfalls) of these classes, I have learned a LOT about
abstraction, encapsulation, inheritance, getters and setters, and manipulating displays to be "human readable."
And, I'm thinking that's a good thing out here on the ranch....
Thank you again pardners!

 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic