• Register
Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

How to get current week start and end date in Java

0 votes
16 views
How to get current week start and end date in Java?
asked Mar 1 in Java by Rituparna Debroy

1 Answer

0 votes
package com;

import java.util.Calendar;
import java.util.Date;

public class CurrentWeek {

    public static void main(String[] args) {
        Calendar currentCalendar = Calendar.getInstance();
        currentCalendar.setFirstDayOfWeek(Calendar.MONDAY);
        Date currentWeekStart = currentCalendar.getTime();

        currentCalendar.add(Calendar.DATE, 6); //add 6 days after Monday
        Date currentWeekEnd = currentCalendar.getTime();

        System.out.println("Week Start Date: " + currentWeekStart);
        System.out.println("Week End Date: " + currentWeekEnd);
    }
}

Output:-
Week Start Date: Thu Mar 01 13:00:29 IST 2018
Week End Date: Wed Mar 07 13:00:29 IST 2018
answered Mar 1 by ranju_12 (1,740 points)
...