0

How can I know the name of the day of the week in which the month ends, if I have the name of the day in which it begins (Monday, Tuesday, Wednesday ...) and the month (January, February ...), for example, as I know the name of the week of January ends with you if you start on Monday.

  • 1
    use some of the java time classes? have you tried anything? – juju Apr 28 '20 at 22:08
  • can you check whether this post answers your question? :) https://stackoverflow.com/a/5122016/2200312 – Caio Oliveira Apr 28 '20 at 22:40
  • Does this answer your question? [Is there a date format to display the day of the week in java?](https://stackoverflow.com/questions/5121976/is-there-a-date-format-to-display-the-day-of-the-week-in-java) – Caio Oliveira Apr 28 '20 at 22:41

1 Answers1

0

There are many ways to find day-of-week of the last day in month using java.time classes, for example:

LocalDate firstDay = LocalDate.of(2018, 1, 1);
DayOfWeek firstDOW = firstDay.getDayOfWeek();
LocalDate lastDay = YearMonth.of(firstDay.getYear(), firstDay.getMonth()).atEndOfMonth();
DayOfWeek lastDOW = lastDay.getDayOfWeek();

LocalDate lastDay2 = LocalDate.of(firstDay.getYear(), firstDay.getMonth(), firstDay.lengthOfMonth());

LocalDate lastDay3 = firstDay.plusDays(firstDay.lengthOfMonth() - firstDay.getDayOfMonth());

Nowhere Man
  • 19,170
  • 9
  • 17
  • 42