Avoid legacy classes
Among the many problems with the terrible old date-time classes bundled with the earliest versions of Java is their whacky numbering. Months of the year are numbered 0-11 for January-December.
Never use these legacy classes, Calendar
, Date
, etc.
java.time
Use only java.time classes.
Apparently you want the current date.
ZoneId z = ZoneId.of( "Africa/Tunis" ) ;
LocalDate today = LocalDate.now( z ) ;
If you want to switch month but keep the year and day-of-month, use withMonth
method.
LocalDate ld = today.withMonth( Month.JANUARY ) ;
To quote the Javadoc:
Returns a copy of this LocalDate with the month-of-year altered.
If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
Since it seems that you want the name of the day of the week in uppercase in English, this is straightforward:
System.out.println( ld.getDayOfWeek() ) ;
SUNDAY
getDayOfWeek
returns a DayOfWeek
enum constant. If you need a String
, use its toString
method.