import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class cc {
public static void main(String[] args) {
List<String> Yeardates=new ArrayList();
//循环输出2014到2020年每一天
for (int year = 2014; year < 2021; year++) {
Yeardates.addAll(cc.getDaysByYear(year));
}
for (int i = 0; i < Yeardates.size(); i++) {
System.out.println(Yeardates.get(i));
}
}
public static List<String> getDaysByYear(int year){
Calendar c=Calendar.getInstance();
List<String> dates=new ArrayList<String>();
for(int i=0;i<12;i++){
c.set(year,i,1);
int lastDay=c.getActualMaximum(Calendar.DATE);
for(int j=1;j<=lastDay;j++){
String month="";
String day="";
if(i<9) month="-0"+(i+1);
else month="-"+(i+1);
if(j<10) day="-0"+j;
else day="-"+j;
String date=year+month+day;
System.out.println(date);
dates.add(date);
}
}
return dates;
}
}
效果如下: