- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to get day of week for the last day of each month in 2019
For last day of each month, at first create a List collection for day of week −
List<DayOfWeek>dayOfWeek = new ArrayList<>();
Now, get day of week for the last day of each month in 2019, set the year using withYear() and use lastDayOfMonth() and getDayOfWeek methods −
for (Month m: Month.values()) { DayOfWeek days = LocalDate.now().withYear(2019).with(m).with(TemporalAdjusters.lastDayOfMonth()).getDayOfWeek(); }
Example
import java.time.DayOfWeek; import java.time.LocalDate; import java.time.Month; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] argv) { List<DayOfWeek>dayOfWeek = new ArrayList<>(); for (Month m: Month.values()) { DayOfWeek days = LocalDate.now().withYear(2019).with(m).with(TemporalAdjusters.lastDayOfMonth()).getDayOfWeek(); dayOfWeek.add(days); } System.out.println("Last day of each month in 2019 = "+dayOfWeek); } }
Output
Last day of each month in 2019 = [THURSDAY, THURSDAY, SUNDAY, TUESDAY, FRIDAY, SUNDAY, WEDNESDAY, SATURDAY, MONDAY, THURSDAY, SATURDAY, TUESDAY]
- Related Articles
- Get the last day of month in Java
- Java Program to get day of week as string
- Java Program to get display name for Day of Week in different locale
- Java Program to get the day of the week from GregorianCalendar
- Get Day Number of Week in Java
- How to get last day of a month in Python?
- How to get last day of the current month in MySQL?
- How to get last day of the previous month in MySQL?
- How to get last day of the next month in MySQL?
- Get the week number in MySQL for day of week?
- How to get day of month, day of year and day of week in android using offset date time API class?
- Get the day of week for a particular date in Java
- Finding day of week from date (day, month, year) in JavaScript
- C# Program to get current day of week
- Determine day of week in month from Gregorian Calendar in Java

Advertisements