- 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 the beginning and end date of the week
At first, set a date:
LocalDate date = LocalDate.of(2019, 4, 16);
Now, get the date for the beginning of the week:
LocalDate start = date; while (start.getDayOfWeek() != DayOfWeek.MONDAY) { start = start.minusDays(1); }
Now, get the date for the end of the week:
LocalDate end = date; while (end.getDayOfWeek() != DayOfWeek.SUNDAY) { end = end.plusDays(1); }
Example
import java.time.DayOfWeek; import java.time.LocalDate; public class Demo { public static void main(String[] argv) { LocalDate date = LocalDate.of(2019, 4, 16); System.out.println("Date = " + date); LocalDate start = date; while (start.getDayOfWeek() != DayOfWeek.MONDAY) { start = start.minusDays(1); } System.out.println("Start of the Week = " + start); LocalDate end = date; while (end.getDayOfWeek() != DayOfWeek.SUNDAY) { end = end.plusDays(1); } System.out.println("End of the Week = " + end); } }
Output
Date = 2019-04-16 Start of the Week = 2019-04-15 End of the Week = 2019-04-21
- Related Articles
- Java Program to get date for all the days of the current week
- Get beginning and end date from a specific year in MySQL
- Java Program to remove whitespace from the beginning and end of a string
- How to get a week start and end date based on a specific date in Excel?
- Java Program to get the seconds since the beginning of the Java epoch
- Get the day of week for a particular date in Java
- Java Program to get the day of the week from GregorianCalendar
- Get the Day of the Week from Today's Date in Java
- Java Program to subtract week from current date
- Java Program to get day of week as string
- How to get beginning of the first day of this week from timestamp in Android sqlite?
- Add elements at beginning and end of LinkedList in Java
- Java Program to check the beginning of a string
- Java Program to get current date, year and month
- Java Program to Get Current Date/Time

Advertisements