51,411
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date d1 = sdf.parse("2013");
Date d2 = new Date();
Calendar ca = Calendar.getInstance();
ca.setTime(d1);
while (ca.getTime().before(d2)){
String str = sdf.format(ca.getTime());
ca.add(Calendar.YEAR,1);
System.out.println(str);
}
}
返回结果:
2013
2014
2015
2016
2017