java日期遍历

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class Test0003 {
    
    public static void main(String args[]) {
        //请注意月份是从0-11
        Calendar start = Calendar.getInstance();
        start.set(2014,2, 1);
        Calendar end = Calendar.getInstance();
        end.set(2014, 3, 1);
        
        int sumSunday = 0;
        int sumSat = 0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        while(start.compareTo(end) <= 0) {
            int w = start.get(Calendar.DAY_OF_WEEK);
            if(w == Calendar.SUNDAY)
                sumSunday ++;
            if(w == Calendar.SATURDAY)
            sumSat ++;
            //打印每天
            System.out.println(format.format(start.getTime()));
            //循环,每次天数加1
            start.set(Calendar.DATE, start.get(Calendar.DATE) + 1);
        }
        System.out.println("星期天总数为:" + sumSunday);

        System.out.println("星期六总数为:" + sumSat);

}

}