一切不多说,上源码!
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestTime {
public static void main(String[] args) {SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
String datestr="2016-12-11";
String dateend="";
int countdate=0;
do{
countdate++;
Date date2 =null;
try {
date2 = sdf.parse(datestr); /*先将字符串转换成日期格式*/
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calendar = new GregorianCalendar();
calendar.setTime(date2);
calendar.add(calendar.DATE,countdate);//把日期往后增加一天.整数往后推,负数往前移动
Date todate=calendar.getTime();
dateend =sdf.format(todate);
System.out.println(dateend);
}while(!dateend.equals("2017-02-11")); /**do--while循环结束**/
}
}