根據指定月份判斷有多少天

bingguang1993發表於2018-06-20

package test;

import java.util.Calendar;

public class test2 {

/**
* @param args
*/
public static void main(String[] args) {
int year = 2017;
int month = 3;
Calendar c = Calendar.getInstance();
c.set(year, month, 0); //輸入型別為int型別

int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
System.out.println(year + "年" + month + "月有" + dayOfMonth + "天");

}

}

相關文章