Here you can find the source of getLastDayOfPreviousPeriod(int startDayOfPeriod, Calendar cal)
public static Date getLastDayOfPreviousPeriod(int startDayOfPeriod, Calendar cal)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static Date getLastDayOfPreviousPeriod(int startDayOfPeriod) { Calendar cal = Calendar.getInstance(); return getLastDayOfPreviousPeriod(startDayOfPeriod, cal); }//w w w. j av a2 s.co m public static Date getLastDayOfPreviousPeriod(int startDayOfPeriod, Calendar cal) { int huidigeDagVdMaand = cal.get(Calendar.DAY_OF_MONTH); if (huidigeDagVdMaand >= startDayOfPeriod) { int diff = huidigeDagVdMaand - startDayOfPeriod; cal.add(Calendar.DAY_OF_MONTH, -(diff + 1)); } else { cal.add(Calendar.DAY_OF_MONTH, -huidigeDagVdMaand); while (cal.get(Calendar.DAY_OF_MONTH) >= startDayOfPeriod) { cal.add(Calendar.DAY_OF_MONTH, -1); } } cal.clear(Calendar.MILLISECOND); cal.clear(Calendar.SECOND); cal.clear(Calendar.MINUTE); cal.clear(Calendar.HOUR); return cal.getTime(); } }