首页 > 代码库 > 日历 java方法实现

日历 java方法实现

package ppt11util类;

import java.util.Calendar;

public class TprintCalendar {
    public static void main(String[] args) {
        printCalendar(2017,6);
    }
    public static void printCalendar(int year,int month){
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MONTH,(month-1));
        cal.set(Calendar.YEAR,year);
        //1号是周几
        int what = cal.get(Calendar.DAY_OF_WEEK);
        for (int i = 0; i < what; i++) {
            System.out.print("\t");
        }
        for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH);
                i++) {
            System.out.print(i+"\t");
            if((what+i)%7==0){
                System.out.println("");
            }
        }
    }
}

 

日历 java方法实现