获取一年中的所有周六周日对应的日期

2021-05-31  本文已影响0人  i小雨
public static void main(String[] args) {
        int year =2021;
        Calendar calendar=new GregorianCalendar(year,0,1);
        int i=1;
        while(calendar.get(Calendar.YEAR)<year+1){
            calendar.set(Calendar.WEEK_OF_YEAR,i++);
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
            if(calendar.get(Calendar.YEAR)==year){
                System.out.printf("星期天:%tF%n",calendar);
            }
            calendar.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
            if(calendar.get(Calendar.YEAR)==year){
                System.out.printf("星期六:%tF%n",calendar);
            }
        }
    }
上一篇下一篇

猜你喜欢

热点阅读