Last active
May 18, 2016 07:31
-
-
Save olkunmustafa/3d7552459d68dca1e2c152c7a675c952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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