aspose file tools*
The moose likes Beginning Java and the fly likes Java  DateFormatSymbols using getWeekdays() method shows Text version of day of week Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java  DateFormatSymbols using getWeekdays() method shows Text version of day of week" Watch "Java  DateFormatSymbols using getWeekdays() method shows Text version of day of week" New topic
Author

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

Roberta Fine
Greenhorn

Joined: Apr 23, 2013
Posts: 27
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.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

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

Joined: Apr 23, 2013
Posts: 27
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!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java DateFormatSymbols using getWeekdays() method shows Text version of day of week