Skip to content

Instantly share code, notes, and snippets.

@olkunmustafa
Last active May 18, 2016 07:31
Show Gist options
  • Save olkunmustafa/3d7552459d68dca1e2c152c7a675c952 to your computer and use it in GitHub Desktop.
Save olkunmustafa/3d7552459d68dca1e2c152c7a675c952 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) {
List<String> afterdays = new ArrayList<String>();
List<String> beforeDays = new ArrayList<String>();
SimpleDateFormat df = new SimpleDateFormat( "dd-MM-yyyy" );
// Set edilmediği sürece bugün tarihini döner.
Calendar cal = Calendar.getInstance();
int calday = (int) ( cal.getTimeInMillis() / ( 1000 * 60 * 60 * 24 ) );
// After days
Calendar sixMonthsLater = (Calendar) cal.clone();
sixMonthsLater.add( Calendar.MONTH, 6 );
int sixMonthsLaterDay = (int) ( sixMonthsLater.getTimeInMillis() / ( 1000 * 60 * 60 * 24 ) );
for (int i = 0; i < sixMonthsLaterDay - calday; i++) {
Calendar dayAfter = (Calendar) cal.clone();
dayAfter.add( Calendar.DAY_OF_MONTH, i );
afterdays.add( df.format( dayAfter.getTime() ) );
}
// Before days
Calendar sixMonthsbefore = (Calendar) cal.clone();
sixMonthsbefore.add( Calendar.MONTH, -6 );
int sixMonthsBeforeDay = (int) ( sixMonthsbefore.getTimeInMillis() / ( 1000 * 60 * 60 * 24 ) );
for (int i = 0; i < calday - sixMonthsBeforeDay; i++) {
Calendar dayBefore = (Calendar) cal.clone();
dayBefore.add( Calendar.DAY_OF_MONTH, -i );
beforeDays.add( df.format( dayBefore.getTime() ) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment