Fetching the first date of a week in java

calendar, date, datetime, java, simpledateformat

Solution

I would do it this way

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(Currentdate);
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

Problem

I would like to fetch the first date of a week. My input is going to be a String type like 07/26/2014". I need to get the first date of week in which the above date(07/26/2014) falls. I need output date in MM/dd/YYYY format . basically I need output as 07/21/2014. Please give me the java program. I have done upto this ``` SimpleDateFormat formatter1 = new SimpleDateFormat("MM/dd/yy"); String date ="07/26/2014"; Date Currentdate = formatter1.parse(date); int currentday=Currentdate.getDay(); Calendar calendar = Calendar.getInstance(); calendar.setTime(Currentdate); int startDay=currentday-calendar.getFirstDayOfWeek(); Currentdate.setDate(contacteddate.getDate()-startDay); System.out.println(contacteddate.getDate()); } ``` The above code only gives me the date.. I need date along with month and year in "MM/dd/YYYY" Please help

Original source

Related problems