- 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 adjust LocalDate to last Day of Month with TemporalAdjusters class
Let us first set a date:
LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15)
Now, adjust LocalDate to last Day of month;
LocalDate day = localDate.with(TemporalAdjusters.lastDayOfMonth());
Example
import java.time.LocalDate; import java.time.Month; import java.time.temporal.TemporalAdjusters; public class Demo { public static void main(String[] args) { LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15); System.out.println("Current Date = "+localDate); System.out.println("Current Month = "+localDate.getMonth()); LocalDate day = localDate.with(TemporalAdjusters.firstDayOfMonth()); System.out.println("First day of month = "+day); day = localDate.with(TemporalAdjusters.lastDayOfMonth()); System.out.println("Last day of month = "+day); day = localDate.with(TemporalAdjusters.firstDayOfNextMonth()); System.out.println("First day of next month = "+day); } }
Output
Current Date = 2019-06-15 Current Month = JUNE First day of month = 2019-06-01 Last day of month = 2019-06-30 First day of next month = 2019-07-01
- Related Articles
- Java Program to adjust LocalDate to first Day of Month with TemporalAdjusters class
- Java Program to adjust Adjust LocalDate to first Day Of next month with TemporalAdjusters class
- Java Program to adjust LocalDate to last Day of Year with TemporalAdjusters class
- Java Program to adjust LocalDate to next Tuesday with TemporalAdjusters class
- Java Program to get day of week for the last day of each month in 2019
- Get the last day of month in Java
- How to get last day of a month in Python?
- Convert day of year to day of month in Java
- 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?
- How to display first day and last day of the month from date records in MySQL?
- Java Program to convert LocalDate to java.util.Date
- Java Program to convert java.util.Date to LocalDate
- Java Program to add Period to LocalDate

Advertisements