Find start and end date of week from input date in java

06 Jun

// set the date e.g. 12 June 2015
Calendar cal = Calendar.getInstance();
cal.set(2015, 6 – 1, 12);

// “calculate” the start date of the week
Calendar first = (Calendar) cal.clone();
first.add(Calendar.DAY_OF_WEEK, first.getFirstDayOfWeek() – first.get(Calendar.DAY_OF_WEEK));

// and add six days to the end date
Calendar last = (Calendar) first.clone();
last.add(Calendar.DAY_OF_YEAR, 6);

// print the result
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd”);
System.out.println(df.format(first.getTime()) + ” -> ” +

2015-06-08 -> 2015-06-14

Leave a comment

Posted by on June 6, 2015 in Android Source Code


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: