Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getStartOfNextWeek(String DATE){
- String format = "dd.MM.yyyy";SimpleDateFormat df = new SimpleDateFormat(format);
- Date date = null;
- try {
- date = df.parse(DATE);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- int week = cal.get(Calendar.WEEK_OF_YEAR);
- int year = cal.get(Calendar.YEAR);
- Calendar calendar = new GregorianCalendar();
- calendar.clear();
- calendar.set(Calendar.YEAR, year);
- calendar.set(Calendar.WEEK_OF_YEAR, week);
- //add 8 days to get next weeks Monday
- calendar.add(Calendar.DAY_OF_WEEK, 8);
- Date startDate = calendar.getTime();
- SimpleDateFormat df2 = new SimpleDateFormat("dd.MM.yyyy");
- String start = df2.format(startDate);
- return start;
- input: 15.12.2014
- output: 22.12.2014 CORRECT
- input: 22.12.2014
- output: 29.12.2014 CORRECT
- input: 29.12.2014
- output: 6.1.2014 WRONG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement