场景:利用Java语言输出连续某一段时间固定格式的时间信息
Java代码
String startDate = "20150916";
String endDate = "20150919";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date1 = sdf.parse(startDate);
Date date2 = sdf.parse(endDate);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date1);
while (!calendar.getTime().equals(date2)) {
System.out.println(sdf.format(calendar.getTime()));
calendar.add(Calendar.DATE, 1);
}
20150916
20150917
20150918