Inconvenient old time classes, such as java.util.Calendar , are now deprecated, being superseded by java.time classes.
java.time.DayOfWeek enum
Java now includes a java.time.DayOfWeek enumeration.
Skip the objects of this enumeration, and not just the integers 1-7, to make your code more self-documenting, provide security by type, and provide a range of valid values.
invoices.printReportForDayOfWeek( DayOfWeek.MONDAY );
Numbering is 1-7 from Monday to Sunday, according to ISO 8601.
Get the localized day name by calling getDisplayName .
String output = DayOfWeek.MONDAY.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) ;
To track several days of the week, use EnumSet (implementation of Set ) or EnumMap (implementation of Map ).
Set<DayOfWeek> weekend = EnumSet.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY ) ; … Boolean todayIsWeekend = weekend.contains( LocalDate.now( ZoneId.of( "America/Montreal" ) ).getDayOfWeek() );
About java.time
The java.time framework is built into Java 8 and later. These classes supersede old inconvenient time classes such as java.util.Date , .Calendar and java.text.SimpleDateFormat .
The Joda-Time project, now in maintenance mode , advises switching to java.time.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations.
Most java.time functions return to Java 6 and 7 in ThreeTen-Backport and are further adapted to Android in ThreeTenABP .
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter , etc.