![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 next Tuesday with TemporalAdjusters class
At first, set a LocalDate:
LocalDate localDate = LocalDate.of(2019, Month.FEBRUARY, 2);
Now, adjust the LocalDate to next Tuesday using next() method:
LocalDate date = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
Example
import java.time.DayOfWeek; 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.FEBRUARY, 2); System.out.println("Current Date = "+localDate); System.out.println("Current Month = "+localDate.getMonth()); LocalDate date = localDate.with(TemporalAdjusters.firstDayOfMonth()); System.out.println("First day of month = "+date); date = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY)); System.out.println("Next Tuesday date = "+date); } }
Output
Current Date = 2019-02-02 Current Month = FEBRUARY First day of month = 2019-02-01 Next Tuesday date = 2019-02-05
Advertisements