My requirement is to get the start and end date of the week when date is passed. I have searched and i found tons of answers but confused with which one is best to use.In one of the thread i found the below code:
Calendar c = Calendar.getInstance();
c.setTime(new Date("8/16/2017"));
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
System.out.println("day :" + dayOfWeek);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
System.out.println("start of week day :" + c.getTime());
output:
day :4
start of week day :Sun Aug 13 00:00:00 EDT 2017
I see a bug in the above code output. Start of the week should be Monday Aug14 but it shows Sun Aug13. Any suggestions to get the start date and end date of the week when date is passed as a String dynamically.
--EDITED-- I'm looking for java code which returns the first and last day date's of the week when date is passed.