import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class TestDate {
public static void main(String[] args) {
try {
List
String start = "21/07/2011";
String end = "08/08/2011";
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
DateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd");
Date startD = (Date) formatter.parse(start);
Date endD = (Date) formatter.parse(end);
long ara = 24 * 1000 * 60 * 60;
long endTime = endD.getTime();
long time = startD.getTime();
while (time <= endTime) {
days.add(new Date(time));
time += ara;
}
for (int i = 0; i < days.size(); i++) {
Date d = (Date) days.get(i);
String day = outFormatter.format(d);
System.out.println(day);
}
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
No comments:
Post a Comment