My Problem: I wanted a String in which at the start of the Program, the Name of tomorrows Weekday is saved.
Basically, if I start the Program on Monday, it calls a Method and the String has the Value "Tuesday".
Is there an easy way to do it ?
My Problem: I wanted a String in which at the start of the Program, the Name of tomorrows Weekday is saved.
Basically, if I start the Program on Monday, it calls a Method and the String has the Value "Tuesday".
Is there an easy way to do it ?
If you are using Java 8 or later, you could try this using the java.time package:
LocalDate date = LocalDate.now().plusDays(1);
String dayName = date.getDayOfWeek().toString();
See the java.time Tutorial.
I would go with something like that (Java 8):
LocalDateTime date = LocalDateTime.now();
do {
date = date.plusDays(1);
} while(date.getDayOfWeek().getValue() >= 5);
String nextDayName = date.format(DateTimeFormatter.ofPattern("EEEE"));
Possibly, isolate the date acceptance criteria in a separate method for easier future improvements.